Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation组件对同个元素进行2次动画,第二次会无限循环 #2

Open
nornor opened this issue Jan 28, 2015 · 1 comment

Comments

@nornor
Copy link

nornor commented Jan 28, 2015

window.s3LT = new mo.Animation({
        target: $('.s3_layer_lt'),
        fillMode: 'forwards',
        duration: 500,
        iteration: 1,
        keyframes: {
            0: {'opacity': '0', easing: 'ease-in-out'},
            100: {'opacity': '1'}
        }
    });
s3LT.on("end",function(){
window.s3LTBack = new mo.Animation({
    target: $('.s3_layer_lt'),
    fillMode: 'forwards',
    duration: 500,
    iteration: 1,
    keyframes: {
        0: {'opacity': '0', easing: 'ease-in-out'},
        100: {'transform': 'translate3d(0,0,0)', easing: 'ease-in-out'}
    }
});
})

第一个动画on end的时候再针对本身DOM初始化一个新的动画,此时head标签会无限插入新的animation

@lyushine
Copy link
Contributor

可以考虑用class或者class里的属性来判别 end start避免无限循环
var $snowball = $("#snowball");
$snowball.on('webkitAnimationStart',function(e){
if($(this).hasClass("s2_snowball_out")){
score = score+randTempdom;
sendScore(score);
}else if($(this).hasClass("s2_snowball_in")){
randTempdom = random();
var snowUrl = "";
if(randTempdom == 50){
snowUrl = "http://7vihcx.com1.z0.glb.clouddn.com/gameA/mobile/images/s2_star5.png";
}else if(randTempdom <50&& randTempdom>19){
snowUrl = "http://7vihcx.com1.z0.glb.clouddn.com/gameA/mobile/images/s2_star4.png";
}else if(randTempdom <20&& randTempdom>7){
snowUrl = "http://7vihcx.com1.z0.glb.clouddn.com/gameA/mobile/images/s2_star3.png";
}else if(randTempdom <7&& randTempdom>2){
snowUrl = "http://7vihcx.com1.z0.glb.clouddn.com/gameA/mobile/images/s2_star2.png";
}else if(randTempdom){
snowUrl = "http://7vihcx.com1.z0.glb.clouddn.com/gameA/mobile/images/s2_star1.png";
}
$(".s2_snowball img").attr("src",snowUrl);
}
});

$snowball.on('webkitAnimationEnd',function(e){
  if($(this).hasClass("s2_snowball_out")){
    $snowball.removeClass('s2_snowball_out');
    $snowball.addClass('s2_snowball_in');

  }else if($(this).hasClass("s2_snowball_in")){
    $snowball.removeClass('s2_snowball_in');
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants