[英]How to implement long-press event using Polymer1.0?
It seems like long-press event is not part of the Polymer's specifications. 好像长按事件不是Polymer的规格的一部分。
How would you implement that ? 你会如何实现?
I thought about using a behavior and using down
and up
event with some debounce
tricks to manage such a new event but that means I have to make a custom element to use this behavior and can't for example use it directly on any elements I want like : 我想过使用一个行为并使用down
和up
事件以及一些debounce
技巧来管理这样一个新事件,但这意味着我必须创建一个自定义元素来使用这种行为,并且不能直接在我想要的任何元素上使用它喜欢 :
<div on-long-press="_cheese">...</div>
which is not convenient. 这不方便。
Would you have other solutions ? 你有其他解决方案吗?
You don't have to make a custom element for this. 您不必为此创建自定义元素。 This is what polymer behaviors are for. 这就是聚合物行为的用途。 They provide a way for different polymer elements to share common behaviors. 它们为不同的聚合物元素提供了分享共同行为的途径。
As for the actual javascript for implementing the long-press you can get ideas from this question . 至于实现长按的实际javascript,你可以从这个问题中获得想法。
You can use a Vaadin gesture for this. 您可以使用Vaadin手势。
https://github.com/vaadin/vaadin-context-menu/blob/master/vaadin-long-touch.html https://github.com/vaadin/vaadin-context-menu/blob/master/vaadin-long-touch.html
<paper-button on-vaadin-long-touch="function"></paper-button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.