Team:SYSU-China/js/hoverdelay.js

From 2014.igem.org

Revision as of 06:14, 10 October 2014 by MoriWiFi (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

(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, that = this;
       return $(this).each(function(){
           $(this).hover(function(){
               clearTimeout(outTimer);
               hoverTimer = setTimeout(function(){sets.hoverEvent.apply(that)}, sets.hoverDuring);
           },function(){
               clearTimeout(hoverTimer);
               outTimer = setTimeout(function(){sets.outEvent.apply(that)}, sets.outDuring);
           });    
       });
   }      

})(jQuery);