How to use scrollTop in jQuery when scrolling within a div?

Posted by sharataka on Stack Overflow See other posts from Stack Overflow or by sharataka
Published on 2012-11-01T04:58:42Z Indexed on 2012/11/01 4:59 UTC
Read the original article Hit count: 124

Filed under:
|
|
|
|

I am trying to get the scrollTop using jQuery to work when the content I am trying to scroll to is located in within a div. The current implementation doesn't do anything

javascript

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

<script>
    $(document).ready(function (){
            //$(this).animate(function(){
                $('html, body').animate({
                    scrollTop: $("#test4").offset().top
                     }, 2000);
            //});
    });
</script>

html

<div class="row">
    <div class = "span12">

        <div class = "row">

            <div class = "span2">

                <div style="height:480px;font:12px Georgia, Garamond, Serif;overflow:auto;">

                    <div id = "test1">Test1</div>
                    <div id = "test2">Test2</div>
                    <div id = "test3">Test3</div>
                    <div id = "test4">Test4</div>

                </div>
            </div>


            <div class = "row">
                <div class = "span8">
                    Other content on the page
                </div>
            </div>

        </div>
    </div>
</div>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery