Skip to content Skip to sidebar Skip to footer

Jquery Javascript Scrolltop Not Working As Expected On Chrome To Restore Scrollbar Position

I'm using the following jQuery Javascript to save the scrollbar position before the unload event and reapply it again: $(document).ready(function () { document.documentElement.

Solution 1:

This is an older post but I was having the same issue with Chrome 20. Using jQuery 1.7.1 this worked for me:

$(window).on('load', function(){
    $('html body').scrollTop(0);
});

Solution 2:

Before Chrome 10 this use to work like a charm... now it seem to only work in Firefox (Anyone have tested in IE9 ?)

var y = $(window).scrollTop();
$('html, body').animate({scrollTop:(y + 50)}, 1000);

Solution 3:

Scrolling the <body> in Chrome and Safari doesn't work very well, or possibly at all. I don't know why but I once had a similar problem and I fixed it by using a <div> nested inside the <body>.

Solution 4:

This is the code I use (tho the site I'm working on is still in build stage, but this works):

$(document).ready(function(){
    $(window).scroll(function(){
        var posY = $(document).scrollTop();
        $('#trigger').click(function(){
            if($.browser.webkit){
                $('body').stop().animate({scrollTop:0},'slow');
            }else{
                $('html').stop().animate({scrollTop:0},'slow');
            }
        });
    });
});

Webkit won't scroll to the top when the object being scrolled is 'html', so first I check for browser type (and before you say it I know jQuery.support would be better - like I said still in build stage). Browsers other than webkit accept the 'html' selector, so I use that for all other browsers (annoyingly, using 'html' works in Opera but not Chrome, and using 'body' works in Chrome but not Opera...!).

Post a Comment for "Jquery Javascript Scrolltop Not Working As Expected On Chrome To Restore Scrollbar Position"