gpt4 book ai didi

jquery - 悬停事件在 jQuery 中触发两次(进入和离开时)?

转载 作者:行者123 更新时间:2023-12-03 22:16:46 25 4
gpt4 key购买 nike

$(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com