Skip to content

Instantly share code, notes, and snippets.

@megazalrock
Last active August 29, 2015 14:05
Show Gist options
  • Save megazalrock/acf2e8e2fff8b8e54ff9 to your computer and use it in GitHub Desktop.
Save megazalrock/acf2e8e2fff8b8e54ff9 to your computer and use it in GitHub Desktop.
//ダメな実装
$('#gnav li')
.each(function(){
$(this)
.hover(function(){
}, function(){
$('body')
.on('mousemove', function(){
//このmousemoveはmouseleaveする度にバインドされて、一度に複数回実行されることになる
});
});
});
//ダメじゃない実装
var isMouseOver = false;
$('#gnav li')
.each(function(){
$(this)
.hover(function(){
isMouseOver = true;
}, function(){
isMouseOver = false;
});
});
$('body')
.on('mousemove', function(){
if(!isMouseOver){
//mouseOver時でないとき
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment