screen.width and screen.availwidth difference in javascript

不羁岁月 提交于 2019-11-30 08:05:09

问题


What is the difference between screen.width and screen.availwidth in JavaScript?

On my system both are the same!


回答1:


Some things block some of your viewport, such a history/bookmarks side panel. This includes the taskbar, unless it's on Autohide

Then window.screen.width != window.screen.availWidth. :)

If you are drawing things to the viewport, you ought to use availWidth / availHeight to determine if things are off the viewport etc. Be sure to recalculate on window resize otherwise you won't know when the sidepanel has been closed.

Note that not all of the width given by this property may be available to the window itself. When other widgets occupy space that cannot be used by the window object, there is a difference in window.screen.width and window.screen.availWidth.

Source.




回答2:


window.screen.width -> Returns the width of the screen.

window.screen.availWidth -> Returns the amount of horizontal space in pixels available to the window.

It is best to use availWidth for the exact size available for our component example.



来源:https://stackoverflow.com/questions/5456582/screen-width-and-screen-availwidth-difference-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!