zoukankan      html  css  js  c++  java
  • js兼容性——获取当前浏览器窗口的宽高

    通过onresize事件

     1 window.onresize = function () {
     2     document.title = client().width + "    "+ client().height;
     3 }
     4 
     5 
     6  //获取屏幕可视区域的宽高
     7 function client(){
     8    if(window.innerHeight !== undefined){
     9        return {
    10             "width": window.innerWidth,
    11             "height": window.innerHeight
    12         }
    13     }else if(document.compatMode === "CSS1Compat"){
    14             return {
    15                 "width": document.documentElement.clientWidth,
    16                 "height": document.documentElement.clientHeight
    17             }
    18     }else{
    19        return {
    20             "width": document.body.clientWidth,
    21              "height": document.body.clientHeight
    22        }
    23     }
    24}
    25 
    26 二、获取浏览器宽度和高度-使用懒函数优化
    27 window.onresize = function() {                                
    28     document.title = client().width + "    " + client().height;
    29}
    30 
    31  //获取屏幕可视区域的宽高
    32    !function() {
    33        if(window.innerHeight !== undefined) {
    34             client = function() {
    35                 return {
    36                    "width": window.innerWidth,
    37                    "height": window.innerHeight
    38                 }
    39              }
    40        } else if(document.compatMode === "CSS1Compat") {
    41              client = function() {
    42                  return {
    43                     "width": document.documentElement.clientWidth,
    44                     "height": document.documentElement.clientHeight
    45                   }
    46               }
    47 
    48        } else {
    49              client = function() {
    50                  return {
    51                      "width": document.body.clientWidth,
    52                      "height": document.body.clientHeight
    53                   }
    54              }
    55 
    56         }
    57   }();
  • 相关阅读:
    PHP面向对象练习
    PHP面向对象的特点
    PHP的构造函数和析构函数
    PHP面向对象
    AVL-TREE
    ReentrantLock
    treap-名次树-树堆
    细数那些我们熟悉的 排序!
    数据结构 - trie
    python 凸包(经纬度) + 面积[近似]
  • 原文地址:https://www.cnblogs.com/web-wjg/p/7136899.html
Copyright © 2011-2022 走看看