Skip to content

Instantly share code, notes, and snippets.

@villadora
Created July 12, 2012 06:55
Show Gist options
  • Save villadora/3096362 to your computer and use it in GitHub Desktop.
Save villadora/3096362 to your computer and use it in GitHub Desktop.
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