How to reliably get screen width WITH the scrollbar

前端 未结 9 1190
抹茶落季
抹茶落季 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

    there is nothing after scrollbar so "rest of the window" is what?

    But yes one way to do it is make another wrapper div in body where everything goes and body has overflow:none; height:100%; width:100%; on it, wrapper div also also has 100% width and height. and overflow to scroll. SO NOW...the width of wrapper would be the width of viewport

    See Example: http://jsfiddle.net/techsin/8fvne9fz/

    html,body {
        height: 100%;
        overflow: hidden;
    }
    
    .wrapper {
        width: 100%;
        height: 100%;
        overflow: auto;
    }
    

提交回复
热议问题