gpt4 book ai didi

动画执行后未调用 jQuery Animate 回调?

转载 作者:行者123 更新时间:2023-12-01 00:57:49 26 4
gpt4 key购买 nike

我正在使用 jQuery .animate() 创建无限轮播。我之前使用过 .animate() ,没有任何问题。然而这一次,动画并未完成。

这是一个非常简单的动画,将 margin-left 更改为不同的值。值发生了变化,对我来说它看起来好像已经完成,但该函数没有触发。

这是我的代码:

<script type="text/javascript">
$("#scrollLeft").click(function(){
$("#scrollContent").animate(
{'margin-left':'-714px'},
{queue:false, duration:500},
function(){
alert("finishedLeft");
});
});
$("#scrollRight").click(function(){
$("#scrollContent").animate(
{'margin-left':'-1190px'},
{queue:false, duration:500},
function(){
alert("finishedRight");
});
});
</script>

问题区域是页面底部的轮播。我正在运行 jquery-1.7.1.min.js

我想我的主要问题是,什么可能阻止此函数触发,即使事件看起来好像已经完成?

最佳答案

Watch your syntax.

http://jsfiddle.net/n1ck/HBCn5/

$("#scrollLeft").click(function() {
$("#scrollContent").animate({
'margin-left': '-714px', // don't close out the parameters with parentheses yet ...
queue: false, // continue adding the queue option (if needed)
duration: 500 // and the duration option (if needed) and close after
}, function() {
alert("finishedLeft");
});
});
$("#scrollRight").click(function() {
$("#scrollContent").animate({
'margin-left': '-1190px', // same as above
queue: false,
duration: 500
}, function() {
alert("finishedRight");
});
});​ ​

关于动画执行后未调用 jQuery Animate 回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10826227/

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