-2

I have a DIV that has an overflow-y set to scroll.

.scrolling-div {
width: 85%;
height: 200px;
overflow-y: scroll;
}

Assuming that I have a bunch of content inside this div, I want it to scroll all the way to the bottom of the div on pageload. I actually want to see the animation of the scroll (so the div would start at the top, but then I want to see it scroll to the bottom).

How do I create this with either Javascript, Jquery, or just pure CSS? I also want to be able to control the speed of the scroll animation.

kevinkt
  • 735
  • 12
  • 24

2 Answers2

0
$(function() {
  var wtf    = $('#scroll');
  var height = wtf[0].scrollHeight;
  wtf.scrollTop(height);
});

#scroll {
   width: 200px;
   height: 300px;
   overflow-y: scroll;
 }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="scroll">
ghnome
  • 57
  • 1
  • 7
0

You can use jquery's animate:

$('.scrolling-div').animate({ 
   scrollTop: $('.scrolling-div').prop('scrollHeight')
}, 1000);

See a working example here.

Martin Mendez
  • 1,226
  • 1
  • 9
  • 6