I want to create a div like below:
<div id="upButton"> </div>
<div id="divWithExcessiveContent" style="overflow: hidden; height: 20px;">
content number 1<br/>
content number 2<br/>
content number 3<br/>
content number 4<br/>
...
content number 100<br/>
</div>
<div id="downButton"> </div>
Based on the code above, #divWithExcessiveContent
's content should only be until, perhaps "content number 20"
and the rest are hidden. When #downButton
is clicked, the inside of the div
should scroll down, displaying the content below "content number 20"
.
How can I do that using jQuery?
I've created two jsFiddles for you. Hope this is what you want to do with your item list
You can do the trick by introducing another container div and adjust the height/margin top & bottom to scroll/show next.
<div id="upButton"> </div>
<div id="container" style="overflow: hidden;height: 40px;">
<div id="divWithExcessiveContent" >
content number 1<br/>
content number 2<br/>
content number 3<br/>
content number 4<br/>
content number 5<br/>
...
content number 100<br/>
</div>
</div>
<br>
<div id="downButton" style="border:solid 1px;width:50px;">Button</div>
Jquery:
var i = 0;
$('div#downButton').click( function() {
i = i - 20;
$('div#divWithExcessiveContent').css('margin-top', i + 'px');
});
i) Scrolling like behavior demo
http://jsfiddle.net/vendettamit/4xuV4/
ii) Expandable div to show next element demo
http://jsfiddle.net/vendettamit/kmHPk/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With