— Polymer — 1 min read
Polymer elements can use the standard DOM APIs for creating, dispatching, and listening for events. Polymer also provides annotated event listeners, which allow you to specify event listeners declaratively as part of the element's DOM template.
这个其实就是在标签上使用on-event属性。
需要注意的有:
on-tap
事件代替on-click
事件,提供更好的移动浏览器支持。 直接使用原生的addEventListener
和removeEventListener
直接使用原生的CustomEvent
和dispatchEvent
event.composedPath()
: 包含事件传递过程中所经过的nodes路径列表。 自定义的事件默认无法穿透ShadowDOM边界。可以如下设置:
手势事件的支持是基于Legacy Element的,如果使用Polymer2的class风格定义需要使用mixin:Polymer.GestureEventListeners
注册事件也有两种方式:
Polymer.Gestures.addListener(this, 'tap', e => this.tapHandler(e));
包含以下几种手势事件,包含在e.detail中。
x
—clientX coordinate for event y
—clientY coordinate for event sourceEvent
—the original DOM event that caused the down action x
—clientX coordinate for event y
—clientY coordinate for event sourceEvent
—the original DOM event that caused the up action x
—clientX coordinate for event y
—clientY coordinate for event sourceEvent
—the original DOM event that caused the tap action state
—a string indicating the tracking state: start
—fired when tracking is first detected (finger/button down and moved past a pre-set distance threshold) track
—fired while tracking end
—fired when tracking ends x
—clientX coordinate for event y
—clientY coordinate for event dx
—change in pixels horizontally since the first track event dy
—change in pixels vertically since the first track event ddx
—change in pixels horizontally since last track event ddy
—change in pixels vertically since last track event hover()
-a function that may be called to determine the element currently being hovered