I have a jquery code for observing mouseenter
event on menubar in a site.
menubar.on('mouseenter', 'li.parent.level0', function() {
... function body
});
Now I want to provide a delay such that the event function body executes after 2000 ms
, something like below:
menubar.on('mouseenter', 'li.parent.level0', function() {
delay(2000);
... function body
});
I tried the following:
menubar.on('mouseenter', 'li.parent.level0', function() {
delay(2000);
... function body
});
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
But still it doesn't consider the delay, just executes menu code instantly on mouseenter
.
How to do this ?