How to reliably get screen width WITH the scrollbar

前端 未结 9 1212
抹茶落季
抹茶落季 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 21:59

    This is my solution for removing the 'scrollbar shadow', because scrollWidth didn't work for me:

    canvas.width  = element.offsetWidth;
    canvas.height = element.offsetHeight;
    canvas.width  = element.offsetWidth;
    canvas.height = element.offsetHeight;
    

    It's easy, but it works. Make sure to add a comment explaining why you assign the same value twice :)

提交回复
热议问题