源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Javascript实现获取窗口的大小和位置代码分享

  • 时间:2021-09-29 17:17 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Javascript实现获取窗口的大小和位置代码分享
在Javascript中可以使用OuterWidth,OuterHeight 获取浏览器的大小.用 innerWidth,innerHeight 来获取窗口的大小(除去浏览器边框部分)。对于IE6 及之前版本,要区分是标准模式,还是混杂模式。标准模式使用document.documentElement.clientWidth,document.documentElement.clientHeight;混杂模式使用document.body 的clientWidth,clientHeight。
[u]复制代码[/u] 代码如下:
     (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;              }          }       })();
[img]http://files.jb51.net/file_images/article/201412/201412041532329.png[/img] 获取窗口的位置:IE,chrome,Safari,使用screenLeft,screenTop 来获取窗口距离屏幕左边和屏幕上边的位置。而Firefox不支持此属性,Firefox使用screenXP,screenY 达到同样的效果。
[u]复制代码[/u] 代码如下:
    (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);     })();
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部