Home > Web Front-end > JS Tutorial > Angular4 implements mouse hover 3D tilt effect example sharing

Angular4 implements mouse hover 3D tilt effect example sharing

小云云
Release: 2018-01-22 09:06:18
Original
1860 people have browsed it

This article mainly introduces Angular4 to achieve the 3D tilt effect of mouse hover. It is very good and has reference value. Friends who need it can refer to it. I hope it can help everyone.

What is Angular

Angular is a framework developed and maintained by Google for developing cross-platform applications, suitable for both mobile phones and desktops.

What are the features of Angular

Based on Angular we can build applications for all platforms. For example: Web applications, mobile Web applications, mobile applications and desktop applications, etc.

Through Web Worker and server-side rendering (SSR), achieve the highest rendering speed achievable on today's web platform.

Angular gives you effective control over scalability. Based on RxJS, Immutable.js and other push models, it can adapt to massive data requirements.

What functions does Angular provide

Dynamic HTML
Powerful form system (template driven and model driven)
Powerful view engine
Event processing
Fast Page rendering
Flexible routing
HTTP service
View encapsulation
AOT, Tree Shaking

What is the difference between Angular and AngularJS

No more Controller and Scope
Better componentization and code reuse
Better mobile support
Introduced RxJS and Observable
Introduced Zone.js to provide more intelligent change detection

This The effect is the same as the one on the official website of Smartisan Technology, Didi Portal. The effect is a little off, but overall it’s okay.

Tell me, what is the difficulty in realizing this?

If you write it in native, everyone can write it, but for people who are new to Angular, like me, when I decided to write it, I was I'm confused, I can write natively, but if I'm asked to write in angular, I don't know where to start. . .

Use the angular command to wrap this effect in a command. It will not be too convenient if you want to use it next time (add a command where needed and it will be OK),

1. Operate mouse events and pass parameters in angular instructions,

2. How to obtain the event object of the mouse operation object, the same as the native one

3. How to obtain and operate various attributes of the object

I didn’t know it when I made this. . . Check the blog for information. . Only then did I know that this was written by

 @HostListener('mousemove') onMouseMove(para) {}
 @HostListener('mousemove') onMouseMove(para) {
 let e= para ||window.event;
 }
Copy after login
 export class DirectivesDirective {
 constructor(private el: ElementRef) {
 }
 @HostListener('mousemove') onMouseMove(para) {
 let e= para ||window.event;
 let pTop = this.el.nativeElement.offsetTop;
 ...
 }
}
Copy after login

Once you understand the basic structure above, you can achieve this effect. After all, the logic is the same.

Post the code directly

import {Directive, ElementRef, HostListener} from '@angular/core';
@Directive({
 selector: '[appDirectives]'
})
export class DirectivesDirective {
// public el;
 private distance = 50;
 private rotationMultiple = 0.1
 constructor(private el: ElementRef) {
 this.distance = 50;
 this.rotationMultiple = 0.1
 }
 @HostListener('mousemove') onMouseMove(para) {
 let e= para ||window.event;
 let pTop = this.el.nativeElement.offsetTop;
 let pLeft = this.el.nativeElement.offsetLeft;
 let pWidth = this.el.nativeElement.offsetWidth;
 let pHeight =this.el.nativeElement.offsetHeight;
 if(e.clientX  pHeight/2 || e.clientX > pWidth/2 && e.clientY > pHeight/2) {
 // 3.4
 let pctX =(((e.clientX - pLeft)/ pWidth) - 0.5);
 let pctY = -(((e.clientY - pTop)/ pHeight) - 0.3);
 this.animate(pctX, pctY, this.rotationMultiple, this.distance);
 }
 if(e.clientX  pWidth/2 && e.clientY <p>Wow, this screenshot tool is a bit confusing, really stuck, <br></p><p><img title="" alt="Angular4 implements mouse hover 3D tilt effect example sharing" src="https://img.php.cn/upload/article/000/054/025/1a58ae701751024b2046dcc37339afb9-0.gif"></p><p>Related recommendations: <br> </p><p><a href="//m.sbmmt.com/mysql-tutorials-385031.html" target="_self">jQuery mouseover content animation switching effect implementation code</a></p><p><a href="//m.sbmmt.com/js-tutorial-383323.html" target="_self">Example to explain jquery mouseover navigation underline slide-out effect</a></p><p><a href="//m.sbmmt.com/js-tutorial-379543.html" target="_self">How to implement js to trigger an event after the mouse hovers for a certain period of time</a></p>
Copy after login

The above is the detailed content of Angular4 implements mouse hover 3D tilt effect example sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template