开发者

IE7 viewport dimensions including scrollbars

开发者 https://www.devze.com 2023-01-17 17:08 出处:网络
My definition of \"viewport\" is everything between the browser\'s borders (visible a开发者_如何学Crea + scrollbar)

My definition of "viewport" is everything between the browser's borders (visible a开发者_如何学Crea + scrollbar)

http://xirc.chez.com/ie7.html

As you can see, I tried:

  • document.body VS document.documentElement
  • scroll* client* offset*
  • getBoundingClientRect()
  • html { 100% }
  • body { 100% }

The Internet Explorer 7 bug per say is that offset* and getBoundingClientRect() do not include the scrollbar


Hide the scrollbar, get the width/height in the next line of code and show the scrollbar again.

// Hide scrollbars
document.body.style.overflow = "hidden";
// Get width/height
var width = document.body.offsetWidth;
// Reset scrollbars before the UI repaints
document.body.style.overflow = "";

alert(width);
//-> 1600 (on my display)

This will all happen before the display gets updated, so the scrollbars won't flicker and you'll have the full dimensions.

0

精彩评论

暂无评论...
验证码 换一张
取 消