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

2019-07-29 06:48发布

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()

2条回答
Viruses.
2楼-- · 2019-07-29 06:57

maybe you can try

$(window).scrollLeft(100);
查看更多
The star\"
3楼-- · 2019-07-29 07:12

Please use

$(window).scrollLeft(100);

Or

$(document.body).scrollLeft(100);
查看更多
登录 后发表回答