Tengo los siguientes fragmentos de código
$(document).mousedown(function(event) { doSomething(); } Puedo capturar el evento mousedown con éxito.
Estoy tratando de hacer lo siguiente:
mousedownAlgo como
var mouseStillDown = false; $(document).mousedown(function(event) { mouseStillDown = true; doSomething(); }); function doSomething() { if (!mouseStillDown) { return; } // we could have come back from // SetInterval and the mouse is no longer down // do something if (mouseStillDown) { setInterval("doSomething", 100); } } $(document).mouseup(function(event) { mouseStillDown = false; });var int00; // declared here to make it visible to clearInterval. $('#trigger').mousedown(function(){ int00 = setInterval(function() { repeatingfunction(); }, 50); }).mouseup(function() { clearInterval(int00); }); function repeatingfunction() { // This will repeat // } También puede poner un clearInterval en el evento mouseleave .
¡Implementarías algo de recursividad!
var mouseisdown = false; $(document).mousedown(function(event) { mouseisdown = true; doSomething(); }).mouseup(function(event) { mouseisdown = false; }); function doSomething(){ //Code goes here if (mouseisdown) doSomething(); }