May 9, 2013

If mouse up then call the function

User2156494’s Questions:

I have the following code that calls a function. However, I would like the function to be called only on the event of a Mouse Up.

positionMenu : function(){
        if (positionMenuInvalidated) return;
        positionMenuInvalidated = true;
        setTimeout(_positionMenuNow,1); }

The _positionMenuNow which is called in setTimeout should happen only in the event of a mouse up. How can this condition be satisfied ?

I don’t think its a good idea to check whether the mouse is up or not while executing the timeout. Instead its better if you trigger the timeout after the mouseup has been triggered.

$('body').on('mouseup', function() {
   setTimeOut("_positionMenu()", 1000);

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!