Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
window.width和document.width

网页和浏览器的尺寸

__jquery__中拿到浏览器的尺寸:

$(window).width()
$(window).height()

__jquery__中拿到网页的尺寸:

$(document).width()
$(document).height()

在这里通过window拿到的是浏览器的尺寸,而通过document拿到的是网页的尺寸,网页的尺寸是可能大于浏览器的尺寸的,当浏览器有scrollbar的情况下。

所以在实现viewport时,应该将viewport保持和window一致的尺寸而不是document。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.