向元素添加行为(如点击涟漪)的常用方法是使用自定义属性:<parent click-ripple></parent>
。
否则这里是你如何能够通过这次事件中的任意要素:
点阅定制attribute.js
import {inject} from 'aurelia-framework';
@inject(Element)
export class ClickThroughCustomAttribute {
constructor(element) {
this.element = element;
this.handler = event => this.value.dispatchEvent(event);
}
attached() {
this.element.addEventListener('click', this.handler);
}
detached() {
this.element.removeEventListener('click', this.handler);
}
}
<require from="click-through-custom-attribute"></require>
<button ref="button1>I'm Behind</button>
<button click-through.bind="button1">I'm In Front</button>
如果你知道你元素想要通过点击以始终是父元素,您可以在点击涟漪自定义元素内执行类似以下操作:
import {inject} from 'aurelia-framework';
@inject(Element)
export class ClickRipple {
constructor(element) {
this.element = element;
this.handler = event => this.element.parentElement.dispatchEvent(event);
}
attached() {
this.element.addEventListener('click', this.handler);
... add click ripple behavior ...
}
detached() {
... remove click ripple behavior ...
this.element.removeEventListener('click', this.handler);
}
}
我不明白,在所有 –
@MatthewJamesDavis见澄清编辑。 – DevNebulae