Skip to content

Instantly share code, notes, and snippets.

@madrobby
Created July 5, 2011 19:45
Show Gist options
  • Save madrobby/1065712 to your computer and use it in GitHub Desktop.
Save madrobby/1065712 to your computer and use it in GitHub Desktop.
Little Zepto "delayed hover" plugin, using this with backbone.js events
// (c) 2011 Thomas Fuchs
(function($){
$.fn.delayedHover = function(){
var timeout = null, hovering = false, element = this;
function enter(){
element.trigger('delayed_hover:enter');
timeout = null;
hovering = true;
}
function leave(){
element.trigger('delayed_hover:leave');
timeout = null;
hovering = false;
}
function reset(){
if(timeout) clearTimeout(timeout);
timeout = null;
}
element.bind('mouseover', function(){
if(hovering)
reset();
else
if(!timeout) timeout = setTimeout(enter, 250);
});
element.bind('mouseout', function(){
if(hovering){
if(timeout) reset();
timeout = setTimeout(leave, 150);
} else {
reset();
}
});
}
})(Zepto);
@aamirafridi
Copy link

Pass the delay time as an option to the plugin instead of hardcoding it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment