JQuery achieves the effect of processing the time delay of mouse passing through events _ jquery

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.