jQuery的动画在无限循环 [英] jQuery animate in infinite loop
问题描述
我试图做到这一点:
-
prevent一个从提交表单提交按钮
prevent a submit button from submitting the form
淡出元素了
然后提交表单
但我坚持用动画的无限循环!为什么?
But am stuck with an infinite loop of animation! Why??
HTML
<form id="postitron" method="post" action="/postitron/answertron.php">
<input type="hidden" name="acces" value"yes">
<input id="submit" type="submit" value="DOIT">
</form>
JavaScript的
JavaScript
$('#postitron').submit(function(e){
e.preventDefault();
$('#page').animate({opacity:0},400, function(){
$('#postitron').submit();
});
});
PS-我也试过。一()
方法,而不是 .submit()
,但它prevents的从#postitron执行提交方法一次动画的完成:(
P.S.- I've also tried the .one()
method instead of .submit()
, but it prevents the submit method from being executed on #postitron once the animation's complete :(
推荐答案
这是因为你结合你对事件提交
和您的。动画回调函数
是提交
ING形式......导致无限循环。
It is because you are binding your event on SUBMIT
, and your .animate callback function
is SUBMIT
'ing the form...causing the infinite loop.
试试这个:
而不是在格式
,绑定。点击$绑定事件
.submit
C $ C>事件的提交
按钮。
Instead of binding event .submit
on form
, bind .click
event on submit
button.
$('#submit').click(function(e){
e.preventDefault();
$('#page').animate({opacity:0},400, function(){
$('#postitron').submit();
});
});
的裸记住我没有测试这一点。的
这篇关于jQuery的动画在无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!