当我尝试在jquery中使用slidetoggle属性时,我遇到了一些问题。 我想要完成的是:
我试过这个:
$i++;
$("#items"+ $i).click(function(){
$("#items'.$i.'-submenu").slideToggle('slow', function() {
if ( $("#item'.$i.'s-submenu").is(":visible")) {
$("#items'.$i.'").css("border-right","none");
}
else
{
$("#items'.$i.'").css("border-style","solid solid solid solid");
$("#items'.$i.'").css("border-right-width","1px");
}
});
return false;
});
稍后编辑:
HTML看起来像:
<div class="item">Click here </div>
<div class="content">There it goes the hidden content</div>
<div class="item">Click here </div>
<div class="content">There it goes the hidden content</div>
<div class="item">Click here </div>
<div class="content">There it goes the hidden content</div>
<div class="item">Click here </div>
<div class="content">There it goes the hidden content</div>
<div class="item">Click here </div>
<div class="content">There it goes the hidden content</div>
<div class="item">Click here </div>
<div class="content">There it goes the hidden content</div>
<div class="item">Click here </div>
<div class="content">There it goes the hidden content</div>
<div class="item">Click here </div>
<div class="content">There it goes the hidden content</div>
.....................
答案 0 :(得分:1)
使用您的HTML更新
新jQuery
$(".item").click(function(e) {
$(this).next(".content").slideToggle().siblings(".content").each(function(i) {
if ($(this).is(":visible")) $(this).slideToggle();
});
});
你可以使用jQueryUI accordion,但如果你想自己做,那就不难了。
代码如下:
基本HTML布局
<div class="item">
<p class="clickable">Click Here</p>
<div class="content">
I'm open!
<br />
I'm open!
<br />
I'm open!
</div>
</div>
<hr />
<div class="item">
<p class="clickable">Click Here</p>
<div class="content">
I'm open!
<br />
I'm open!
<br />
I'm open!
</div>
</div>
<hr />
<div class="item">
<p class="clickable">Click Here</p>
<div class="content">
I'm open!
<br />
I'm open!
<br />
I'm open!
</div>
</div>
<hr />
<div class="item">
<p class="clickable">Click Here</p>
<div class="content">
I'm open!
<br />
I'm open!
<br />
I'm open!
</div>
</div>
<hr />
<div class="item">
<p class="clickable">Click Here</p>
<div class="content">
I'm open!
<br />
I'm open!
<br />
I'm open!
</div>
</div>
一个lil CSS
.content { display: none; }
.clickable { cursor: pointer; }
最后一些jQuery
$(".item").click(function(e) {
$(this).siblings().each(function(i) {
if ($(this).children(".content").is(":visible")) $(this).children(".content").slideToggle();
});
$(this).children(".content").slideToggle();
});