gpt4 book ai didi

javascript - 单击时向右和向左移动 div

转载 作者:行者123 更新时间:2023-11-30 07:09:29 25 4
gpt4 key购买 nike

我想让 div 在我第一次点击它时向左移动,第二次回到原来的位置,第三次再次向左移动等等。

那么为什么这不起作用: http://jsfiddle.net/kS7KE/2/

    var checker = new Boolean();
checker = true;
if (checker = true){
$("#div").click(function () {
$(this).animate({left: "10%"},400);
checker = false;
});
}
if (checker != true){
$("#div").click(function () {
$(this).animate({left: "30%"},400);
checker = true;
});
}

最佳答案

为什么有这么多代码? :)

var checker = true;
$("#div").click(function () {
targetLeft = checker ? "10%" : "30%";
$(this).animate({left: targetLeft},400);
checker ? checker = false : checker = true;
});

http://jsfiddle.net/kS7KE/5/

关于javascript - 单击时向右和向左移动 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15981585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com