gpt4 book ai didi

jquery动画问题

转载 作者:行者123 更新时间:2023-12-01 07:34:06 25 4
gpt4 key购买 nike

我正在使用 .animate() 创建一个“简单”动画菜单来放大用户悬停在其上的菜单项。这几乎可以正常工作,但是如果用户快速移动光标,它会产生一些奇怪的事情。另外,元素并不总是同时动画。

显示它的最简单方法是使用以下链接。

http://jsfiddle.net/322c5/2/

<head>
<script src="jquery-ui/js/jquery-1.4.2.min.js"></script>
<script>
$(document).ready(function(){

$("#test1").hover( function () {
$(this).animate( { width:"599px",left:"0px", height:"168px" }, 100 )
},
function () {
$(this).animate( { width:"246px",left:"9px", height:"84px" }, 100 )
}
);

$("#test2").hover( function () {
$(this).animate( { width:"599px",left:"0px", height:"168px", top:"-21px" }, 100 )
$(".test").animate( { top:"-21px" }, 100 )
},
function () {
$(this).animate( { width:"246px",left:"9px", height:"84px", top:"0px" }, 100 )
$(".test").animate( { top:"0px" }, 100 )
}
);

$("#test3").hover( function () {
$(this).animate( { width:"599px",left:"0px", height:"168px", top:"-63px" }, 100 )
$(".test").animate( { top:"-63px" }, 100 )
},
function () {
$(this).animate( { width:"246px",left:"9px", height:"84px", top:"0px" }, 100 )
$(".test").animate( { top:"0px" }, 100 )
}
);

$("#test4").hover( function () {
$(this).animate( { width:"599px",left:"0px", height:"168px", top:"-84px" }, 100 )
$(".test").animate( { top:"-84px" }, 100 )
},
function () {
$(this).animate( { width:"246px",left:"9px", height:"84px", top:"0px" }, 100 )
$(".test").animate( { top:"0px" }, 100 )
}
);



});

</script>
<style type="text/css">
.container {
width:599px; background-color:#000;padding:0px; height:336px; overflow-y:hidden;
}

.test {
width:246px; background-color:#039; left:9px; top:0px; position:relative; height:84px;
}
</style>
</head>

<body>

<div class="container">
<div id="test1" class="test">
test
</div>
<div id="test2" class="test">
test
</div>
<div id="test3" class="test">
test
</div>
<div id="test4" class="test">
test
</div>
</div>

</body>

有什么想法吗?

谢谢

最佳答案

这是我的解决方案: http://jsfiddle.net/azLMc/

我向每个 mouseleave() 函数添加了一个clearQueue() 调用。这将停止鼠标悬停动画,并立即执行鼠标离开动画。如果没有它,鼠标悬停动画将继续运行,如果鼠标在完成之前离开该区域,则不会注册需要运行鼠标悬停动画。

之后,当鼠标快速离开文档时,第一个DIV仍然卡住。所以我在 .container DIV 中添加了 mouseleave() 来将第一个 DIV 返回到正常大小,并且有点“重置”。

关于jquery动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3840944/

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