admin管理员组文章数量:1353470
I wonder if it is possible to center the horizontal scroll bar of my site using JavaScript or jQuery. A scroll bar appears for users who use resolutions like 1024 x 768, and therefore, would like her position always stay in the center.
Example:
.png
I wonder if it is possible to center the horizontal scroll bar of my site using JavaScript or jQuery. A scroll bar appears for users who use resolutions like 1024 x 768, and therefore, would like her position always stay in the center.
Example:
https://i.sstatic/YK8Xe.png
Share Improve this question asked Mar 6, 2014 at 16:37 user2297392user2297392 1-
Even if you could, I don't think it would be good practice. If you don't want part of your site hidden for specific screen resolutions, you should make the site responsive. But if you really want to do this, you could add
margin: 0 auto
to center the page. – apohl Commented Mar 6, 2014 at 16:39
1 Answer
Reset to default 10Given that the scrollable element in question is document.body
you could use the following JavaScript to centre the horizontal scrollbar:
document.body.scrollLeft = (document.body.scrollWidth - document.body.clientWidth) / 2
本文标签: javascriptCenter the horizontal scroll bar of my siteStack Overflow
版权声明:本文标题:javascript - Center the horizontal scroll bar of my site - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743932058a2564026.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论