$(document).ready(function(){
$("#menu a").hover(function(){
$(this).animate({opacity: 0.25}, function(){
$(this).animate({opacity: 1});
});
});
});
我将此效果应用于我的菜单,因此当鼠标移到链接上时,它会显示此淡入淡出效果,但是当鼠标从链接上释放时,该效果会再次播放。不应该。当鼠标悬停在链接上时,它应该只播放一次,而不是当鼠标移出时播放一次。
最佳答案
.hover()
有两个回调,一个用于 mouseenter
,一个用于 mouseleave
。
使用 mouseenter
可能会更好:
$(document).ready(function(){
$("#menu a").mouseenter(function() {
$(this).animate({opacity: 0.25}, function(){
$(this).animate({opacity: 1});
});
});
});
关于jquery - 悬停事件在 jQuery 中触发两次(进入和离开时)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8739112/