jquery implements the delay processing effect of the mouse after event _jquery

Source: Internet
Author: User

jquery mouse through (hover) event delay processing, 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 $ (a). 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 a total of four parameters, which means the following:
hoverduring delay time of mouse passing
outduring The time delay of mouse moving out
hoverevent Mouse Execution method
outevent mouse out of the way to execute
The purpose of this function is to allow the mouse to be separated by event and delay, and the delay and delay clearance are resolved by this method. All you have to do is set the time scale for the delay, and the corresponding mouse pass or remove event. For a Simple example , the following code:

$ ("#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!"). "); 
  } 
});

The implication is that the element with the ID test pops up after 200 milliseconds after the mouse passes through me! The pop-up box for the text typeface.

The above is about the jquery mouse through (hover) events of the delay to deal with all the content, I hope to help you learn.

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.