如何在动画完成后更改页面

时间:2015-11-03 10:50:25

标签: jquery animation

所以我想在动画完成后用另一个更改当前页面,问题是我在动画期间调用了一个函数,我真的需要这个函数。目前动画开始,但不会更改页面。

var a = $("#m").offset().left + 75;
var b = $(window).width()/2;

if (a > b) {
    $("#m").animate({
       left: $(window).width(),
    }, { step: function(val){
        dim();
    }}, function(){
        window.location.href = "video.html";
    });
}else if (a - 150 < b){
    $("#m").animate({
        left: -$(window).width(),
    }, { step: function(val){
        dim();
    }},function(){
        window.location.href = "photo.html";
    });
};

1 个答案:

答案 0 :(得分:2)

您可以使用&#34;完成&#34;函数来自jquery animate docs,如

$("#m").animate({
             left: $(window).width(),
             },
             { step: function(val){
                          dim();
                     }, 
               complete: function(){
                          window.location.href = "video.html";
               }
             });
相关问题