-1

I just couldn't find any tips on that, any one may know a way of doing that ?

EDIT: the goal is to trigger a ripple effect on a button https://lv-ripple.antoniodalsie.com, to using $('#button').trigger('mousedown') works but the animation is way too short, it uses timestamps given in events object i think.

Kwaadpepper
  • 516
  • 4
  • 15
  • 1
    Have you at least tried anything? Also some code to explain why you want to do this in the first place may help as there maybe a better and even simpler way – Canvas Sep 11 '16 at 11:55
  • What do you mean by hold it for x seconds? – Tom el Safadi Sep 11 '16 at 11:56
  • Think about it, there's no way to measure the length of a mousedown event, other than listening for the mouseup event ... – adeneo Sep 11 '16 at 11:57
  • 2
    Just do `$(element).trigger('mousedown')` and then after a given time, do `$(element).trigger('mouseup')` and you should have simulated a mouse button being held down for a given time. – adeneo Sep 11 '16 at 12:05
  • 1
    Why are there three answers explaining how to bind an event and measuring the time rather than how to **trigger** it _with a specified time_, which is what this question is actually asking? – Sebastian Simon Sep 11 '16 at 12:06
  • Yes i did that, and i noticed that a mouseup had to be set automatically somehow, i tested on https://lv-ripple.antoniodalsie.com/, because i want to trigger a ripple effect manually, you can test on a button and see how fast it is. I think the lib is using timestamps passed on the events – Kwaadpepper Sep 11 '16 at 12:08
  • Did you try just triggering a `click`? I'm not sure I get this. – adeneo Sep 11 '16 at 12:12

1 Answers1

-3

You can do that following (refer to http://api.jquery.com/mousedown/):

   var interval;
    $(button).addEventListener('mousedown',function(e) {
        interval = setInterval(function() {

        },500); 
    });
    $(button).addEventListener('mouseup',function(e) {
        clearInterval(interval);
    });
    $(button).addEventListener('mouseout',function(e) {
        clearInterval(interval);
    });
zubair1024
  • 843
  • 8
  • 24
  • 1
    What do event listeners have anything to do with the question? The question is about **triggering** events with certain time intervals, not *listening* to events. – Bakuriu Sep 11 '16 at 12:46