$(“html”).scrollLeft(value); not working in Chrome

2019-07-29 06:44发布

问题:

I'm trying to make the browser scroll horizontally to a specific position when the page loads. It works in FF and IE, but not Chrome.

 $(document).ready(function () {
 $("html").scrollLeft(100);
 });

Any ideas?

My larger goal is to have the browser center the horizontal scrollbar. Again, I have it all working in FF and IE, but no Chrome.

All my other methods are working fine in Chrome. I'm using the following methods to find the amount of pixels to scroll so I can center it, and they all work right, but when it comes to try and use "scrollLeft" it does nothing.

$(document).width()
screen.width)
$(window).width()

回答1:

Please use

$(window).scrollLeft(100);

Or

$(document.body).scrollLeft(100);


回答2:

maybe you can try

$(window).scrollLeft(100);