jQuery的动画在无限循环 [英] jQuery animate in infinite loop

查看:765
本文介绍了jQuery的动画在无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做到这一点:


  1. prevent一个从提交表单提交按钮

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆