如何使用Polymer1.0实现长按事件? [英] How to implement long-press event using Polymer1.0?

查看:182
本文介绍了如何使用Polymer1.0实现长按事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



您如何实现这一点?



我想到了一些行为,并使用下来 up 事件与一些去抖动来管理这样一个新事件的技巧,但这意味着我必须使一个自定义元素来使用这个行为,例如直接使用它,就像我想要的任何元素一样:

 < div on-long-press =_ cheese> ...< / div> 

这不方便。



你有其他解决方案吗?

解决方案

您不必为此创建自定义元素。这是聚合物行为所适用的。它们为不同的聚合物元素提供了一种共享共同行为的方法。



对于实现长按的实际javascript,您可以从这个疑问


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 ?

解决方案

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.

这篇关于如何使用Polymer1.0实现长按事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆