js获取浏览器当前屏幕的宽度和高度

1.获取HTML元素

    document.documentElement

2.获取body元素

    document.body

3.兼容所有浏览器获取当前屏幕的宽度。

   var winWidth = document.body.clientWidth || document.documentElement.clientWidth;

4.兼容所有浏览器获取当前屏幕的高度。

  var winHeight = document.body.clientHeight || document.documentElement.clientHeight;

猜你喜欢

转载自blog.csdn.net/sinat_35538827/article/details/81176293