欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Javascript實(shí)現(xiàn)獲取窗口的大小和位置代碼分享

 更新時(shí)間:2014年12月04日 15:36:38   投稿:hebedich  
這篇文章主要分享了一段Javascript實(shí)現(xiàn)獲取窗口的大小和位置代碼,兼容性非常好,這里推薦給大家

在Javascript中可以使用OuterWidth,OuterHeight 獲取瀏覽器的大小.用 innerWidth,innerHeight 來獲取窗口的大?。ǔg覽器邊框部分)。對(duì)于IE6 及之前版本,要區(qū)分是標(biāo)準(zhǔn)模式,還是混雜模式。標(biāo)準(zhǔn)模式使用document.documentElement.clientWidth,document.documentElement.clientHeight;混雜模式使用document.body 的clientWidth,clientHeight。

復(fù)制代碼 代碼如下:

     (function () {
         var pageWidth = window.innerWidth;
         var pageHeight = window.innerHeight;
         var broswerWidth = window.outerWidth;
         var broswerHeight = window.outerHeight;
         alert(pageWidth + " " + pageHeight);
         alert(broswerWidth + " " + broswerHeight);
         if (typeof pageWidth != "number") {
             if (document.compatMode == "CSS1Compat") {  //The standard mode
                 pageWidth = document.documentElement.clientWidth;
                 pageHeight = document.documentElement.clientHeight;
             } else {
                 pageWidth = document.body.clientWidth;
                 pageHeight = document.body.clientHeight;
             }
         } 
     })();

獲取窗口的位置:IE,chrome,Safari,使用screenLeft,screenTop 來獲取窗口距離屏幕左邊和屏幕上邊的位置。而Firefox不支持此屬性,F(xiàn)irefox使用screenXP,screenY 達(dá)到同樣的效果。

復(fù)制代碼 代碼如下:

    (function btnFun() {
        var leftPos = (typeof window.screenLeft == "number") ? window.screenLeft :
            window.screenX;
        var topPos = (typeof window.screenTop == "number") ? window.screenTop :
                         window.screenY;
        alert(leftPos + " " + topPos);
        //alert(window.screenLeft+" "+window.screenTop);
    })();

相關(guān)文章

最新評(píng)論