JQuery-handle the latency of a hover event with the mouse. The specific JS Code is as follows:
(function($){ $.fn.hoverDelay = function(options){ var defaults = { hoverDuring: 200, outDuring: 200, hoverEvent: function(){ $.noop(); }, outEvent: function(){ $.noop(); } }; var sets = $.extend(defaults,options || {}); var hoverTimer, outTimer; return $(this).each(function(){ $(this).hover(function(){ clearTimeout(outTimer); hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring); },function(){ clearTimeout(hoverTimer); outTimer = setTimeout(sets.outEvent, sets.outDuring); }); }); }})(jQuery);
The hoverDelay method has four parameters, which indicate the following:
Delay Time of hoverDuring mouse
Latency of outDuring mouse Removal
How to execute hoverEvent with the mouse
OutEvent mouse Removal Method
The purpose of this function is to let the mouse go through the separation of events and latencies, and to clear the latencies and latencies. All you need to do is set the delay time and the corresponding mouse to go through or remove the event. The following code is a simple example:
$("#test").hoverDelay({hoverDuring: 1000,outDuring: 1000,hoverEvent: function(){$("#tm").show();},outEvent: function(){$("#tm").hide();}});
The following is a more concise case:
$ ("# Test"). hoverDelay ({hoverEvent: function () {alert ("Pass me! ");}});
It indicates that the element with the id of test is displayed after the mouse passes through 200 milliseconds and contains "pass by me !" Text dialog box.
Articles you may be interested in
- Js shields mouse and keyboard events (including right-click, direction key, backspace key, F5 refresh key, etc.), compatible with IE and firefox
- Jquery simulates Mouse clicking events
- Solution to failure of jquery live change event under IE
- Js: Click enter and move the cursor to the next input box.
- Escape user-passed variables, from ecshop
- How to Prevent event bubbling in JQuery and Its Differences
- How does js determine whether the scroll wheel is scroll down or up?
- A classic dialogue between programmers and testers. These are shared by foreign programmers, who say they are used globally?