带注释的监听器
添加事件侦听器的另一种方法是在 DOM 中使用 on-event
注释。下面是使用 up
事件的示例,当手指/鼠标上升时会触发该事件
<dom-module id="annotated-listener">
<template>
<style>
.inner{
width: calc(200px);
height: 50px;
border: 1px solid blue;
margin-top: 15px;
}
</style>
<!-- As up is the name of the event annotation will be on-up -->
<div class="inner" on-up='upEventOccurs'>Tap me for different alert</div>
</template>
</dom-module>
<script>
Polymer({
is:'annotated-listener',
upEventOccurs:function(e){
//detail Object in event contains x and y co-ordinate of event
alert('up event occurs at x:'+e.detail.x+' y:'+e.detail.y);
}
})
</script>