This article mainly introduces how jQuery achieves the latency processing of mouse-over-event processing. For details, refer to the latency processing of jQuery mouse-over-event (hover). 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:
HoverDuring Latency of the mouse
OutDuring Latency of mouse Removal
HoverEvent How to run the mouse
OutEvent How to move the mouse
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. For exampleSimple ExampleThe following code:
$("#test").hoverDelay({ hoverDuring: 1000, outDuring: 1000, hoverEvent: function(){ $("#tm").show(); }, outEvent: function(){ $("#tm").hide(); } });
The following is a more conciseCase:
$ ("# 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.
The above describes how to handle all the content about the delay of jQuery mouse passing through (hover) events. I hope this will be helpful for your learning.