我想让 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;
});
关于javascript - 单击时向右和向左移动 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15981585/