0
Would there be any way to detect the touch pressed on a button? The code works normally on desktop, but when will I test in mobile does not act.
Use the Jquerymobile is not an option.
var timeout = 0;
$('button').mousedown(function() {
timeout = setTimeout(menu_toggle, 2000);
}).bind('mouseup mouseleave', function() {
clearTimeout(timeout);
});
function menu_toggle() {
alert('ok');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>pressionar</button>
Why don’t you use the event
click
?– Woss
For mobile/touchscreen has a specific set of events:
touchstart
,touchend
,touchmove
,touchcancel
.– bfavaretto
Not just click, I need to press for a few seconds.
– Diego Vieira
I edited my answer and tested on my mobile and works well.
– user60252