JavaScript:如何在浏览器窗口中找出视点的宽度和高度? [英] JavaScript: How to find out width and height of viewpoint in browser window?

查看:34
本文介绍了JavaScript:如何在浏览器窗口中找出视点的宽度和高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在浏览器窗口中找出视点的宽度和高度?以及如何找出有多少文件上下滚动?

How to find out width and height of viewpoint in browser window? And How to find out how much document scrolled to down and to right?

推荐答案

尝试使用此函数...,并在需要时调用它:)

Try this function... and call it when needed :)

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:如何在浏览器窗口中找出视点的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆