How to implement long-press event using Polymer1.0?

三世轮回 提交于 2020-01-24 04:34:26

问题


It seems like long-press event is not part of the Polymer's specifications.

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 :

<div on-long-press="_cheese">...</div>

which is not convenient.

Would you have other solutions ?


回答1:


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.




回答2:


You can use a Vaadin gesture for this.

https://github.com/vaadin/vaadin-context-menu/blob/master/vaadin-long-touch.html

<paper-button on-vaadin-long-touch="function"></paper-button>



来源:https://stackoverflow.com/questions/31005504/how-to-implement-long-press-event-using-polymer1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!