Always visible div while scrolling

M Usman Shafique picture M Usman Shafique · Jan 24, 2012 · Viewed 40.6k times · Source

On my aspx page, I have two left and right portions. I want to show always left side (which is actually a 'div' containig treeview) while scrolling the right side (which are actual contents of page). Thanks

Answer

Despertaweb picture Despertaweb · Apr 10, 2013

Hi I found the best solution! As always JQUERY saving my life !!

Just put a Div called as you wan, I've chosen the same in the example below: #scrollingDiv.

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script>
    $().ready(function() {
        var $scrollingDiv = $("#scrollingDiv");

        $(window).scroll(function(){            
            $scrollingDiv
                .stop()
                .animate({"marginTop": ($(window).scrollTop() )}, "slow" );         
        });
    });
</script>

I took that code from a website, it works and it's pretty easy to understand.