Daljeet Dhaliwal
Daljeet Dhaliwal

Reputation: 55

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

Upvotes: 0

Views: 2138

Answers (2)

TriniBoy
TriniBoy

Reputation: 690

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...');
});

Upvotes: 1

Pierre Tasci
Pierre Tasci

Reputation: 450

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

Upvotes: 0

Related Questions