只是让这个代码隐藏div,直到点击标题,效果很好,只是现在我有三个div在彼此之下,我只想要第一个扩展,然后当另一个被点击时一个是开放的,一个是扩大的。我的Jquery在下面
$(function(){
$('.drop-dwn').click(function(){
$(this).next('.slide1').slideToggle(300);
return false;
});
});
我的HTML标记是:
<div class="slide-panels">
<h4 class="drop-dwn">Oil & Gas</h4>
<div class="slide1">
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
</div>
<h4>SAP & Enterprise Solutions</h4>
<div class="slide2">
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
</div>
<h4>IT & Change Management</h4>
<div class="slide3">
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
</div>
</div>
答案 0 :(得分:0)
<div class="slide-panels">
<h4 class="drop-dwn">Oil & Gas</h4>
<div class="first slide1">
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
</div>
<h4 class="drop-dwn">SAP & Enterprise Solutions</h4>
<div class="slide1">
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
</div>
<h4 class="drop-dwn">IT & Change Management</h4>
<div class="slide1">
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
<div class="checkbox"><input type="checkbox" name="" value=""> All</div>
</div>
</div>
jQuery的:
$('.first').slideDown(300);
$(function(){
$('.drop-dwn').click(function(){
$('.slide1').slideUp(300);
$(this).next('.slide1').slideToggle(300);
return false;
});
});
CSS:
.slide1{
display:none;
}
答案 1 :(得分:0)
诀窍是滑动所有div,然后滑动你点击的那个。
所以给所有div一个像'panel'和
这样的公共类$('.drop-dwn').click(function(){
var _this = this;
$(".panel").slideUp("fast", function() {
$(_this).slideDown("fast");
});
});