如何在浏览器窗口中找出视点的宽度和高度?以及如何找出有多少文档向下和向右滚动?
最佳答案
试试这个函数...并在需要时调用它:)
function getViewPortSize()
{
var viewportwidth;
var viewportheight;
//Standards compliant browsers (mozilla/netscape/opera/IE7)
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
// IE6
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0)
{
viewportwidth = document.documentElement.clientWidth,
viewportheight = document.documentElement.clientHeight
}
//Older IE
else
{
viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
viewportheight = document.getElementsByTagName('body')[0].clientHeight
}
return viewportwidth + "~" + viewportheight;
}
关于JavaScript:如何在浏览器窗口中找出视点的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1860524/