简体   繁体   English

按住CSS时是否可能触发事件?

[英]is it possible fire an event on button press and hold in css?

I am working on a project in which i want a menu to appear on screen whenever it is touched and hold. 我正在一个项目中,希望在触摸并按住菜单时将其显示在屏幕上。 So I want to know that just like button click and hover property in CSS is there any way to implement click and hold property, if no then how it can be done using javascript or jquery. 因此,我想知道,就像CSS中的按钮单击和悬停属性一样,有任何方法可以实现单击并保留属性,如果没有,那么如何使用javascript或jquery来实现。

thanks 谢谢

You can do this using jQuery, a combination of mousedown , mouseup and mouseleave 您可以使用jQuery(结合mousedownmouseupmouseleave来完成此操作

Fiddle 小提琴

<button class="testHold">click and hold me</button>
<div class="tracker"></div>


$('.testHold').mousedown(function() {
    $('.tracker').html("holding holding holding");
}).bind('mouseup mouseleave', function() {
    $('.tracker').text('free as a bird...');
});

There is no truly native way to accomplish this. 没有真正的本机方法可以做到这一点。 You can check out this solution for a good workaround using jquery's draggable plugin. 您可以使用jquery的Draggable插件来查看该解决方案,以获得一个好的解决方法。

Trigger Click-and-Hold Event 触发点击并保持事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM