jQuery - slide down instead of slide up

独自空忆成欢 提交于 2019-12-13 00:41:05

问题


How to make the same as jsFiddle, but the difference is the green box should slide down to disappear (and slide up to appear when you click the click here link in the example one more time).

The two strings

/*position:absolute;*/
/*bottom:0px;*/

which are commented in the css part of jsFiddle doesn't work well if uncomment because it really starts to slide down, but the browser scroll bar disappers - not good.


回答1:


Edited:

Add a <div> with an id sliderWrapper and give it 100% width as given below.

<div width="100%" id="sliderWrapper">        
    <div id="slider" style="border:1px solid red;">
        <h1>1</h1><h1>2</h1><h1>3</h1><h1>4</h1><h1>F</h1>

        <h1>1</h1><h1>2</h1><h1>3</h1><h1>4</h1><h1>E</h1>

        <h1>1</h1><h1>2</h1><h1>3</h1><h1>4</h1><h1>D</h1>

        <h1>1</h1><h1>2</h1><h1>3</h1><h1>4</h1><h1>C</h1>

        <h1>1</h1><h1>2</h1><h1>3</h1><h1>4</h1><h1>B</h1>

        <h1>A</h1><h1>A</h1><h1>A</h1><h1>A</h1><h1>A</h1>

         <h1>6</h1><h1>7</h1><h1>8</h1><h1>9</h1><h1>10</h1>
    </div>
</div>

Keep following css rules for #slider

  #slider {
      background : green;             
      width:100px;
      margin:20px auto 0 auto;
   }

Replace following line with $('#slider').slideToggle(500)

 if(hid) { $('#sliderWrapper').show("slide", { direction:"down" }, 500);} 
 else { $('#sliderWrapper').hide("slide", { direction:"down" }, 500); }

SEE DEMO




回答2:


Edited your jsFiddle! Used jquery.slideToggle(); and some Css to get the right slide direction!

jsFiddle



来源:https://stackoverflow.com/questions/11859976/jquery-slide-down-instead-of-slide-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!