简体   繁体   中英

jQuery show/hide toggle DIVs

So, I've successfully got a script working that shows/hides divs by clicking on the month.

If you scroll to the bottom of http://kaye.at/test/ and click 'April' or 'May' you can see it working.

The issue is I don't like how it animates sliding out to the left when it's closing, I'd rather it slide down or back up instead, but can't find where in the javascript to amend this?

Here's the JS:

$(document).ready(function() {
  $('.nav-toggle').click(function(){
        //get collapse content selector
        var collapse_content_selector = $(this).attr('href');                   
        //make the collapse content to be shown or hide
        var toggle_switch = $(this);
        $(collapse_content_selector).toggle(function(){
           if($(this).css('display')=='none'){}else{}
        });
   });
});

And the HTML:

<div id="wrapper-alt" class="shade8">
  <div class="content">
    <h1 class="full"><a href="#collapse1" class="nav-toggle shade81">APRIL</a></h1>
  </div>
</div>

<div id="collapse1" style="display:none">
   <div id="wrapper-alt" class="shade8">
     <div class="content">
         Content goes here
     </div>
   </div>
</div>  

Apologies if my JS is messy, I'm a complete amateur, just play around with it for fun and learning!

Also, I've just noticed it doesn't work with multiple DIVs, all links only open the 1 div, how do I use it for multiple different DIVs?

slideToggle() jquery's method

$('.nav-toggle').click(function(){
        //get collapse content selector
        var collapse_content_selector = $(this).attr('href');                   

        //make the collapse content to be shown or hide
        var toggle_switch = $(this);
        $(collapse_content_selector).slideToggle(function(){
          if($(this).css('display')=='none'){}else{          
          }
        });
      });

我最终使用了一个不同的脚本,因为我似乎无法让它正常工作!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM