How to reliably get screen width WITH the scrollbar

前端 未结 9 1203
抹茶落季
抹茶落季 2020-12-03 21:38

Is there a way to reliably tell a browser\'s viewport width that includes the scrollbar, but not the rest of browser window)?

None of the properties listed here tell

9条回答
  •  清歌不尽
    2020-12-03 22:23

    With jQuery you can calculate the browser's scrollbar width by getting the width difference when overflow: hidden is set and overflow: scroll is set. The difference in width will be the size of the scrollbar.

    Here is a simple example that shows how you could do this.

提交回复
热议问题