【发布时间】:2012-03-13 16:55:43
【问题描述】:
我正在尝试为我正在开发的网站制作一个小动画,但是按照我构建它的方式,当我将鼠标移到容器 div 上时,动画仍然会发生。如何让它识别出鼠标实际上没有悬停?
HTML 代码是:
<div id="badge">
<div id="slogan">
<p>We sell for less!</p>
</div>
<div id="icon"></div>
<div id="name"></div>
<div id="TMhold">
<div id="TM"></div>
</div>
</div>
这是我正在使用的 jQuery:
$("#badge").hover(
function() {
$(this).stop(true,true).animate({width: "250px"}, 760, "easeOutQuart");
setTimeout(function() {
$("#TM").stop(true,true).animate({top: "0"}, 500, "easeOutQuart");
}, 500 );
setTimeout(function(pee) {
$('#badge p').stop(true,true).animate({opacity: .99}, 760, "easeOutQuart");
}, 800 );
},
function() {
clearTimeout(pee);
$('#badge p').stop(true,true).animate({opacity: 0}, 120, "easeOutQuart");
setTimeout(function() {
$('#badge').stop(true,true).animate({width: "90px"}, 900, "easeOutQuart");
$("#TM").stop(true,true).animate({ top: "-13px"}, 500, "easeOutQuart");
}, 300 );
}
);
我已阅读有关 clearTimeout 功能的信息,但我不确定这是否适用于我的解决方案。
非常感谢您的帮助或澄清!
【问题讨论】:
-
我建议您练习适当的代码间距和缩进,以帮助提高可读性和故障排除。我编辑了你的帖子以显示我在说什么。
标签: jquery mouseleave jquery-hover