简体   繁体   中英

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.

thanks

You can do this using jQuery, a combination of mousedown , mouseup and mouseleave

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.

Trigger Click-and-Hold Event

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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