动画完成后jQuery更改值 [英] jQuery change value after animation is done

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

问题描述

这段代码从不调用警告'是真的'

This code down never call alert 'ane is true'.

可以从jQuery方法animate更改本地变量'ane'吗?

It is possible to change local variable 'ane' from jQuery method "animate"?

在我的代码变量'ane'总是假的。我尝试使用此方法更改'ane'值:

In my code variable 'ane' is always false. I try this method for change of 'ane' value:

function anim() {
  var ane = false;
  $('#element').animate({left:'100px'}, 5000, function(){ ane = true; });
  while(!ane){}
  alert('ane is true');
}

这对我也不起作用:

function anim() {
  var ane = false;
  var ant = function(){ ane = true; }
  $('#element').animate({left:'100px'}, 5000, ant);
  while(!ane){}
  alert('ane is true');
}

感谢您的回复。

推荐答案

现场演示

function anim() {
  var ane = false;
    $('#element').animate({left:'100px'}, 5000, function(){
        ane = true;
        if(!$(this).is('animated')){
            alert(ane);
        }
    });
}

动画完成后,您将收到提醒。

Once the animation completes you will be alerted.

这篇关于动画完成后jQuery更改值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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