【发布时间】:2014-04-19 19:14:04
【问题描述】:
我有以下 jQuery 代码(我的第一个自制 jQuery 代码,所以不要对我太苛刻:))。 我第一次使用切换开关时,一切都完美无缺:
- 我单击右切换,#content 移动并出现左切换。
- 我单击左侧切换,#content 向后移动并出现右侧切换。 (一切都回到起始位置)。
但在那之后,我的右切换不再是可点击的(虽然它确实出现了)。我想一遍又一遍地做同样的事情(点击右键,#content move等)。但是用我当前的代码,我只能做一次这个动画。
谁能帮帮我:)?
提前谢谢:)
//starting values
$(".rowToggleL").off('click');
$(".rowToggleR").on('click');
//Right Toggle
$(".rowToggleR").click(function () {
// make Toggle Right unclickable, make Toggle Left clickable
$(".rowToggleR").off('click');
$(".rowToggleL").on('click');
//animate contentbox
$("#content").animate({
left: "-=300" // animate to the right
}, 800,
// Animation complete. Make Toggle Right invisible, make Toggle Left visible
function() {
$(".rowToggleR").css("display", "none");
$(".rowToggleL").css("display", "inline");
});
});
//Left Toggle
$(".rowToggleL").click(function () {
// make Toggle Left unclickable, make Toggle Right clickable
$(".rowToggleL").off('click');
$(".rowToggleR").on('click');
//animate contentbox
$("#content").animate({
left: "+=300" // animate to the right
}, 800,
// Animation complete. Make Toggle Left invisible, make Toggle Right visible.
function() {
$(".rowToggleL").css("display", "none");
$(".rowToggleR").css("display", "inline");
});
});
【问题讨论】:
标签: jquery jquery-animate jquery-click-event