在 angular 2 中,我试图使用@angular/animations
一个组件来制作一个<li>
元素跟随鼠标(ondrag)
并在(ondragend)
. 我对角度很陌生,并且非常迷茫解决这个问题的最佳方法是什么。我希望能够将我的组件中的字符串注入到动画中,但不确定这是否可能。请参阅下面的示例。
import { Component } from '@angular/core';
import { trigger, state, style, animate, transition } from '@angular/animations';
@Component({
selector: 'test-test',
template: `
<li
*ngFor="let letter of list"
[@lettereState]="letter.state"
(ondrag)="letter.toggleState(); mouseCords($event.clientX, $event.clientY);"
(ondragend)="letter.toggleState()">
{{letter}}
</li> `,
animations: [
trigger('letterState', [
state('active', style({
transform: //'translate(Inject the cordinates here {mouseX}, {mouseY})',
})),
])
],
})
export class LetterBankComponent {
constructor(
) {}
private list = ['a', 'b', 'c']
private mouseX = ''
private mouseY = ''
}
mouseCords(x, y) {
mouseX = x;
mouseY = y;
}