Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm trying to force mouseup event after mousedown

elements[0].onmousedown = function(){
      console.log('screen clicked.');
      simulatemouseuphere;
};

All I need to do is add something in my function that triggers mouseup, even if the user is holding the click button down.

elements[0] is my entire page scope, so anywhere you click, it will trigger.

like image 213
abejdaniels Avatar asked Nov 22 '25 02:11

abejdaniels


2 Answers

I'm pretty sure you can just call the onmouseup event...

elements[0].onmousedown = function(){
      console.log('screen clicked.');

      elements[0].onmouseup();
};

Keep in mind that when you actually physically stop holding the mouse down though, the mouseup event will be triggered again. (unless in the onmouseup() event you manage that)

Tested quickly, looks like it works: http://jsfiddle.net/cUCWn/40/

like image 191
Spacemonkey Avatar answered Nov 23 '25 14:11

Spacemonkey


$("body").on("mousedown", function(e)
{
    e.type = "mouseup";
    $(this).trigger(e);
}).on("mouseup", function(e)
{
    console.info(e);
});

Or: https://stackoverflow.com/a/12724570/2625561

For pure JS: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events#Triggering_built-in_events

like image 23
klenium Avatar answered Nov 23 '25 14:11

klenium



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!