且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Angular 2 (angular-cli) 中使用 vanilla js 代码

更新时间:2023-09-30 09:56:16

您应该能够导入 Vinilla-tilt 并使用传递给构造函数的元素引用.

You should be able to import Vinilla-tilt and use the element reference passed into the constructor.

import { Directive, ElementRef, HostListener, Input } from '@angular/core';

const VanillaTilt = require('vanilla-tilt');

@Directive({
    selector: '[data-tilt]'
})
export class ParallaxDirective {
    constructor(private el: ElementRef) {
      VanillaTilt.init(el.nativeElement, {
        max: 25,
        speed: 400
      });
    }
}