简体   繁体   English

jQuery显示/隐藏切换DIV

[英]jQuery show/hide toggle DIVs

So, I've successfully got a script working that shows/hides divs by clicking on the month. 所以,我已成功获得一个脚本工作,通过点击月份来显示/隐藏div。

If you scroll to the bottom of http://kaye.at/test/ and click 'April' or 'May' you can see it working. 如果您滚动到http://kaye.at/test/的底部并单击“四月”或“五月”,您可以看到它正常工作。

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? 问题是我不喜欢它在关闭时动画向左滑动​​,我宁愿它向下滑动或向后滑动,但是在javascript中找不到修改它的位置?

Here's the JS: 这是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: 和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! 抱歉,如果我的JS很乱,我是一个完全的业余爱好者,只是为了好玩和学习而玩它!

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? 另外,我刚刚注意到它不适用于多个DIV,所有链接只打开1个div,我如何将它用于多个不同的DIV?

slideToggle() jquery's method slideToggle() jquery的方法

$('.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{          
          }
        });
      });

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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