2

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>

小提琴:http: //jsfiddle.net/jdrVG/

正如标题所说,如果单击其他切换,我如何关闭一个元素?

提前致谢 :-)

4

1 回答 1

1

你可以试试这个。 演示

 $($toggled).siblings(':visible').hide();
于 2013-10-04T00:10:41.083 回答