Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: On hold action

  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Thanked 0 Times in 0 Posts

    On hold action


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

  • #2
    Regular Coder
    Join Date
    Oct 2003
    on a ship
    Thanked 6 Times in 5 Posts
    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(){
    Last edited by brandonH; 11-04-2006 at 11:58 PM.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts