Sunday 15 March 2015

javascript - Trigger a function only once inside a continously triggered function -


I have a function that triggers every mouse down event when the mouse pointer is on the image. Now, I call two functions in this mouse-down function.

I need a function Triangulate () every time and second ImageCalculation () last time only.

The last time only means that the interval of 3 seconds or more continuously should be between img_mouse_down () function calls.

Below is my code:

  function img_mouse_down () {if (leftMouseButton) {Triangulate (); // Call this function every time ImageCalculation (); // Call this function only last time}}   

If I click on the image 5 times continuously and then pause for 3 or more seconds, Triangulate ( ) should be called 5 times and ImageCalculation () should be called only once.

How to get it?

Something that should solve your problem, time expiration is allowed on each call and otherwise ImageCalculation starts after three seconds.

  var timer = null function img_mouse_down () {if (leftMouseButton) {Triangulate (); (Timer! == Faucet) {Clear Timeout} Timer = Set Timeout (function () {Image Seculation ()}, 3000)}}    

No comments:

Post a Comment