这是我的脚本,我正在使用一个切换,这样我就可以为一个滑动的菜单设置动画。
$("div.show-menu").click().toggle(
function() {
// first alternation
$("#slideover").animate({
right: "512px"
}, 300);
$(".menu-button").html('close menu');
}, function() {
// second alternation
$("#slideover").animate({
right: "0"
}, 300);
$(".menu-button").html('open menu');
});虽然我真的需要切换来使用页面上的2个元素。例如,见下文..。
<div class="show-menu one">open menu</div> // this is element one
<div class="show-menu two">open menu</div> // this is element two我需要它,所以,如果元素一首先点击,你可以在第一次点击时使用元素二来关闭菜单。现在的情况是,您必须单击元素2两次才能关闭菜单-反之亦然
我想这就是开关的作用,任何帮助都将是非常感谢的。
干杯乔什
发布于 2011-11-12 01:46:52
$('.show-menu').on('click', function () {
//check the state of the .menu-button, if it's closed then run the open animation, if it's open then run the close animation
if ($(".menu-button").html() == 'close menu') {
$("#slideover").animate({
right: "0"
}, 300);
$(".menu-button").html('open menu');
} else {
$("#slideover").animate({
right: "512px"
}, 300);
$(".menu-button").html('close menu');
}
});.on()是jQuery 1.7中的新功能,在这种情况下它取代了.bind(),如果您使用的是jQuery < 1.7,则使用.bind()。
发布于 2011-11-12 01:50:18
关于
$('.show-menu').on('click', function () {
if ($("#slideover").css("right") == '512px') {
$("#slideover").animate({
right: "0"
}, 300);
$(".menu-button").html('open menu');
} else {
$("#slideover").animate({
right: "512px"
}, 300);
$(".menu-button").html('close menu');
}
});https://stackoverflow.com/questions/8097855
复制相似问题