MouseDOWN for two seconds

Hi,

I need to simulate an ON/OFF switch (which actives after been pressed down for over two seconds). So while the mouse button is pressed DOWN on a button graphic for two seconds the Main Timeline then starts to play again after the two second period so I can continue showing the sequence?

Many thanks,
Ian

Hi,

You can add the following script to the slide On Load event to do that:

var button = prez.object('Your button name');
$(button.node).mousedown(function() {
    button.myMouseDownTimeout = setTimeout(function() {
        delete button.myMouseDownTimeout;
        // continue timeline
        prez.pause(false);
    }, 2000);  // wait for 2s (2000ms)
});
$(document).mouseup(function() {
    if (button.myMouseDownTimeout) {
        clearTimeout(button.myMouseDownTimeout);
        delete button.myMouseDownTimeout;
    }
});

Regards

Thank you so much. This works perfect. I have been trying for ages to get this to work!
I didn’t know your software supports these commands - $(button.node).mousedown. This doesn’t appear to be in your manual. Is that correct or have i missed them?

Again, thank you so much :slight_smile:

Hi,

button.node is the DOM element associated with the button, you can use JavaScript to bind events to it or change its styles… It’s not officially supported so we don’t document it.

$(button.node).mousedown is the way to bind mousedown event to button.node using jQuery library.

Regards

Thank you for explaining it.

Hello Again!

You recently helped me with the above issue - regards having JavaScript activate during a ‘mousedown’ press. I have been informed this does not work on an iPad. Is this true?

Many thanks in advance,
Ian

Hi Ian,

You can use pointerdown/pointerup events instead of mousedown/mouseup events to make it work on almost all modern browsers on computers or mobile devices.

// replace $(button.node).mousedown(function() { by
$(button.node).on('pointerdown', function() {

// replace $(document).mouseup(function() { by
$(document).on('pointerup', function() {

Regards