View Full Version : On hold action

11-04-2006, 10:30 PM

Can we someway create a custom on mouse hold (when you press and hold) function like the on click and on double click etc.. ??

11-04-2006, 11:47 PM
I'm sure you can.

use the onmousedown handler to start a function that sets a varible to '1' and does a setTimeout(). on that same element have a onmouseup handler that sets that variable to '0'. so if the user doesnt hold the mouse down for the duration of the wait for the setTimeout, the variable gets set to '0' and the event you want to happen for the onHold wont happen. but if they hold the mosue down for the entire time of the setTimeout the variable stays set to '1'. and when the setTimeout runs it calls another function that checks that variable, if its '1' it does what you want, if not it does nothing (in my example i hae it alert you).

<input type=button value=hold onmousedown="OnHold();" onmouseup="clearHold();">

function OnHold(){
duration='5';//change this to how many seconds you want the hold to last
function checkHold(){
alert('you held the mouse button down for 5 seconds');}
else{alert('you didnot hold the mouse down long enough to cause the hold trigger');}
function clearHold(){