Skip to content Skip to sidebar Skip to footer

Automatically Scroll Down With Jquery?

I have a modal box with a defined height. Inside of this box there is an accordion box that expands when a user clicks a link. The height of the accordion box when it is toggled ex

Solution 1:

If I understand what you're looking for...

If you'd like a nice smooth scroll, then the scollTo plugin is a great choice.

If you don't care, just use a hash. location.hash = '#someid';

Solution 2:

If you don't want to rely on any plugin, or change the actual URL, you could use scrollTop, see http://api.jquery.com/scrollTop/

Cheers.

Solution 3:

The trick is to use an outer container-div which is scrollable. This allows to find out the size of the inner div which holds the actual content. My solution (You have to do some adjustments for your accordion):

<html><head><style>#container {
            overflow-y: scroll;
            height: 200px; /* defined height */
         }
      </style></head><body><divid="container"><divid="content"><!-- dynamic content --></div></div></body><scripttype="text/javascript"src="http://jquery.com/src/jquery-latest.js" ></script><scripttype="text/javascript">functiononNewContent() {
         $("#container").scrollTop($("#content").height());
      }

      //test
      $(document).ready(function() {
         for(var i = 0; i < 500; ++i)
            $("#content").append($("<div/>").html(i));
         onNewContent();
      });
   </script></html>

Post a Comment for "Automatically Scroll Down With Jquery?"