[英]How to achieve toggle effect with jQuery in this situation?
Found one example that is exactly what I would like to have. 找到了一个我想要的例子。 Please resize your window to 700px less and url is http://www.subway.com.au
请调整您的窗口大小至少700px,网址为http://www.subway.com.au
thanks for reading this. 感谢您阅读本文。
My layout is as the following: 我的布局如下:
<div id="left">
<div id="left-container" style="display:none;">Content foo
</div>
</div>
<div id="right">
<div id="right-container" style="display:none;">Content bar
</div>
</div>
<div class="overlay"></div>
Basically, when click either #left or #right, relatively the #left-container or #right-container will slideUp or slideDown, and at the same time .overlay will be showed or hidden. 基本上,当单击#left或#right时,相对地#left-container或#right-container将会slideUp或slideDown,同时.overlay将被显示或隐藏。 Of course, when containers are slideUp, clicking all screen rather than itself will slideDown and removeClass .overlay.
当然,当容器为slideUp时,单击所有屏幕而不是单击其本身将是slideDown和removeClass .overlay。
I know this question has been brought over a lot of times. 我知道这个问题已经提出很多次了。 However it seems still not working for me.
但是,它似乎仍然对我不起作用。 Thanks for your time.
谢谢你的时间。
I would use a little different HTML for that - 我会为此使用一些不同的HTML-
<div id="left" class="header">
A
<div class="container">Content foo
</div>
</div>
<div id="right" class="header">
B
<div class="container">Content bar
</div>
</div>
<div class="overlay"></div>
and with the JS - 和JS-
$(function(){
$(".header").on("click", function(){
if($(this).find(".container").is(":visible")){
$(".header").find(".container").each(function(){
$(this).slideDown();
});
$(this).find(".container").slideUp();
$(".overlay").show();
}else{
$(this).find(".container").slideDown();
$(".overlay").hide();
}
});
});
Here is the fiddle - http://jsfiddle.net/n8ykqLuy/1/ 这是小提琴-http: //jsfiddle.net/n8ykqLuy/1/
NOTE: At first I thought your requirement was custom. 注意:起初我认为您的要求是自定义的。 But I think what you are looking for is an accordion.
但是我认为您正在寻找的是手风琴。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.