Slide down and slide up div on click

后端 未结 3 751
情话喂你
情话喂你 2020-12-20 22:19

I am using the following code to open and close a div ( slide up/down ) using js

I have the slide down event attached to a button and the slide up event sttached to

相关标签:
3条回答
  • 2020-12-20 23:00

    try this. it allows multiple items so isn't ID specific. and supports any content loaded via AJAX as well. jsfiddle is here

    <div class='toggle_parent'>
      <div class='toggleHolder'>
        <span class='toggler'>Open</span>
        <span class-'toggler' style='display:none;'>Close</span>
      </div>
      <div class='toggled_content' style='display:none;'>
          My Content
      </div>
    </div>
    

    and

    $('.toggler').live('click',function(){
      $(this).parent().children().toggle();  //swaps the display:none between the two spans
      $(this).parent().parent().find('.toggled_content').slideToggle();  //swap the display of the main content with slide action
    
    });
    
    0 讨论(0)
  • 2020-12-20 23:06

    You can just use slideToggle() in the click function:

    $('.grabPromo').click(function(e){
        $('.slideDown').slideToggle();
    });
    

    Here's a demo.

    0 讨论(0)
  • 2020-12-20 23:17
    <div id="content">
    bla bla bla bla bla bla bla bla blabla bla blabla bla bla
    </div>
    <input type="button" id="myButton" value="Slide down ↓"/>
    
    $("#myButton").toggle(function(){
        $("#content").slideDown();
        $(this).val("Slide up ↑");
    },function(){
        $("#content").slideUp();
        $(this).val("Slide down ↓")
    });
    

    Online demo: http://jsfiddle.net/amosrivera/AYWku/

    Demo with span: http://jsfiddle.net/amosrivera/AYWku/1/

    0 讨论(0)
提交回复
热议问题