@HostListener('mousemove') onMouseMove(para) {}
@HostListener('mousemove') onMouseMove(para) {
let e= para ||window.event;
}
export class DirectivesDirective {
constructor(private el: ElementRef) {
}
@HostListener('mousemove') onMouseMove(para) {
let e= para ||window.event;
let divTop = this.el.nativeElement.offsetTop;
...
}
}
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 divTop = this.el.nativeElement.offsetTop;
let divLeft = this.el.nativeElement.offsetLeft;
let divWidth = this.el.nativeElement.offsetWidth;
let divHeight =this.el.nativeElement.offsetHeight;
if(e.clientX < divWidth/2 && e.clientY > divHeight/2 || e.clientX > divWidth/2 && e.clientY > divHeight/2) {
// 3.4
let pctX =(((e.clientX - divLeft)/ divWidth) - 0.5);
let pctY = -(((e.clientY - divTop)/ divHeight) - 0.3);
this.animate(pctX, pctY, this.rotationMultiple, this.distance);
}
if(e.clientX < divWidth/2 && e.clientY < divHeight/2 || e.clientX > divWidth/2 && e.clientY < divHeight/2) {
// 1.2
let pctX =((e.clientX - divLeft)/ divWidth) - 0.7;
let pctY = ((e.clientY - divTop)/ divHeight) - 0.5;
this.animate(pctX, pctY, this.rotationMultiple, this.distance);
}
}
private animate(pctX: number, pctY: number, rotationMultiple: number, distance: number) {
let rotateX = pctY * rotationMultiple * -180;
let rotateY = pctX * rotationMultiple * 180;
this.el.nativeElement.style.transform = ' rotateX(' + rotateX + 'deg' + ')' + ' rotateY(' + rotateY + 'deg'+ ')';
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有