开发者

Implementing smooth div toggle

I am trying to recreate the "div toggle" effect on this page, but with jQuery:

cordon-bleu.se

I want this effect, but working like the above page: the visible div hides when you click to show another:

sohtanaka.com/web-design/easy-toggle-jquery-tutorial/

My javascript so far is:

$(document).ready(function(){

 $("h2.menutrigger").click(function(){
  $('.active').removeClass('active').slideToggle("slow");
  $(this).next().addClass('active').slideToggle("slow");
 });

});

These are the divs I am trying to toggle:

<div class="menuitem active">
 <img src="images/img_header.png" style="margin: 15px auto;"/>
</div>
<h2 class="menutrigger"><a href="#">Historia</a></h2>
<div class="menuitem">
 <p>Bla bla</p>
 <p>Bla Bla</p>
</div>
<h2 class="menutrigger"><a href="#">Spisar</a></h2>
<div clas开发者_运维技巧s="menuitem">
 <p>Bla bla</p>
</div>

And this is my (relevant) css:

.menuitem {
 height: 385px;
 background-color: #000;
 display:none;
}

.active {
 display: block;
}

You can see here how it works right now.

I appreciate any help I can get.


Simple solution would be to remove the display: block; statement from your .active class and let jQuery handle the display setting for you via slideToggle().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜