@Directive({ selector: '[circle]' })
export class MouseWheelDirective {
@Output() mouseWheelUp = new EventEmitter();
@Output() mouseWheelDown = new EventEmitter();
@HostListener('mousewheel', ['$event']) onMouseWheelChrome(event: any) {
this.mouseWheelFunc(event);
}
@HostListener('DOMMouseScroll', ['$event']) onMouseWheelFirefox(event: any) {
this.mouseWheelFunc(event);
}
@HostListener('onmousewheel', ['$event']) onMouseWheelIE(event: any) {
this.mouseWheelFunc(event);
}
mouseWheelFunc(event: any) {
var event = window.event ;
var delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
if(delta > 0) {
this.mouseWheelUp.emit(event);
} else if(delta < 0) {
this.mouseWheelDown.emit(event);
}
}
}
雖然,你可以刪除這些'老IE support'部分,因爲相關的版本不支持'svg'可言。 – naeramarth7