gpt4 book ai didi

javascript - 多个 div 崩溃 : close one element if other is open (jQuery)

转载 作者:行者123 更新时间:2023-11-30 05:43:52 26 4
gpt4 key购买 nike

HTML

<ul id="slider">
<li>
<a class="toggle" href="#g1"><img src="BLAHBLAH" /></a>
<a class="toggle" href="#g2"><img src="BLAHBLAH" style="margin-left:30px;margin-right:30px" /></a>
<a class="toggle" href="#g3"><img src="BLAHBLAH" /></a>
</li>
<li>
<a class="toggle" href="#g4"><img src="BLAHBLAH" /></a>
<a class="toggle" href="#g5"><img src="BLAHBLAH" style="margin-left:30px;margin-right:30px" /></a>
<a class="toggle" href="#g6"><img src="BLAHBLAH" /></a>
</li>
<li>
<a class="toggle" href="#g7"><img src="BLAHBLAH" /></a>
<a class="toggle" href="#g8"><img src="BLAHBLAH" style="margin-left:30px;margin-right:30px" /></a>
<a class="toggle" href="#g9"><img src="BLAHBLAH" /></a>
</li>
</ul>

<div id="g1" class="gallery"><p>gallery 1</p></div>
<div id="g2" class="gallery"><p>gallery 2</p></div>
<div id="g3" class="gallery"><p>gallery 3</p></div>
...

JS:

<script>
$('.toggle').click(function() {
var $toggled = $(this).attr('href');
$($toggled).siblings(':visible').hide("slide", {direction: 'up'}, 750);
$($toggled).toggle("slide", {direction: 'up'}, 750);
return false;
});
</script>

CSS:

<style>
.GALLERY { display: none; padding: 50px 20px 20px 20px; }
</style>

fiddle : http://jsfiddle.net/jdrVG/

如标题所述,如果单击另一个切换按钮,我如何关闭一个元素?

提前致谢:-)

最佳答案

你可以试试这个。 Demo

 $($toggled).siblings(':visible').hide();

关于javascript - 多个 div 崩溃 : close one element if other is open (jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19170916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com