使用 2 个元素进行 Jquery 切换
这是我的脚本,我正在使用切换开关,这样我就可以为滑动菜单设置动画。
$("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
我需要它,如果首先单击元素一,您可以在第一次单击时使用元素二关闭菜单。现在发生的情况是,您必须单击元素二两次才能关闭菜单 - 反之亦然,
我想这是正在发挥作用的切换,任何帮助将非常感谢。
干杯 乔什
this is my script, I'm using a toggle so I can animate a sliding menu.
$("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');
});
Though I really need the toggle to work using 2 elements on the page. For example see below...
<div class="show-menu one">open menu</div> // this is element one
<div class="show-menu two">open menu</div> // this is element two
I need it so, if element one get's click first, you can close the menu using element two on the first click. What is happening now is that you have to click element two twice in order for it to close the menu - vice versa
I guess this is the toggle coming into play, any help would be great thanks.
Cheers
Josh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.on()
是 jQuery 1.7 中的新功能,如果您使用的是 jQuery.bind()
,则在此实例中将替换.bind()
1.7 然后使用.bind()
。.on()
is new in jQuery 1.7 and replaces.bind()
in this instance, if you are using jQuery < 1.7 then use.bind()
.怎么样
What about