如何用jQuery右/左隐藏和显示Divs动画



到目前为止,当我单击事件时,我的应用程序正在工作,div向左移动,下一个div出现了,到目前为止都很好。第一个过渡是有效的,但是当我想回去时,它行不通。

function animate_question(current_question, next_question, direction) {
    if (direction == "left") {
        $(current_question).animate({
            left: "-=100",
            opacity: "0"
        }, {
            "complete": function () {
                $(current_question).remove();
                $(next_question).delay(200).fadeIn();
            }
        });
    } else if (direction == "right") {
        $(current_question).animate({
            left: "+=100",
            opacity: "0"
        }, {
            "complete": function () {
                $(current_question).remove();
                $(next_question).delay(200).fadeIn();
            }
        });
    }
}

编辑

上下文

$("#next2").click(function() {
    var a = check_radio("Q1");
    if(a) {
        animate_question(".question1", ".question2", "left");
    } else {
        alertify.alert(message);
    }
});

$("#back1").click(function() {
    animate_question(".question2", ".question1", "right");
});

remove实际上从dom中删除了元素。如果您再次尝试,就没有动画元素。

最新更新