一、Javascript源码

    if (!window.jasen.core.Position) {
window.jasen.core.Position = {};
} function Size(width, height) {
this.width = parseFloat(width);
this.height = parseFloat(height);
} Size.prototype.toString = function () {
return "width=" + this.width + ";height=" + this.height;
} function Point(x, y) {
this.x = parseFloat(x);
this.y = parseFloat(y);
} Point.prototype.toString = function () {
return "x=" + this.x + ";y=" + this.y;
} // 获取窗口的左上角的偏移量(相对屏幕)
function getScreenOffset() {
if (window.screenLeft) {
return new Point(window.screenLeft, window.screenTop);
}
else if (window.screenX) { // Firefox
return new Point(window.screenX, window.screenY);
} return new Point(0, 0);
} // 获取屏幕的大小
function getScreenSize() {
return new Size(window.screen.width, window.screen.height);
} // 获取窗口中的文档显示区的大小
function getVisibleSize() {
if (window.innerWidth) {
return new Size(window.innerWidth, window.innerHeight);
}
else if (document.documentElement && document.documentElement.clientWidth) {
return new Size(document.documentElement.clientWidth, document.documentElement.clientHeight);
}
else if (document.body && document.body.clientWidth) {
return new Size(document.body.clientWidth, document.body.clientHeight);
} return new Size(0, 0);
} // 获取窗口中的文档的偏移量(滚动条的值)
function getPageOffset() {
if (window.pageXOffset) {
return new Point(window.pageXOffset, window.pageYOffset);
}
else if (document.documentElement && document.documentElement.scrollLeft) {
return new Point(document.documentElement.scrollLeft, document.documentElement.scrollTop);
}
else if (document.body && document.body.scrollLeft) {
return new Point(document.body.scrollLeft, document.body.scrollTop);
} return new Point(0, 0);
} var position = window.Position = window.jasen.core.Position;
position.getScreenOffset = getScreenOffset;
position.getScreenOffsetX = function () { return getScreenOffset().x; };
position.getScreenOffsetY = function () { return getScreenOffset().y; };
position.getScreenSize = getScreenSize;
position.getScreenWidth = function () { return getScreenSize().width; };
position.getScreenHeight = function () { return getScreenSize().height; };
position.getVisibleSize = getVisibleSize;
position.getVisibleWidth = function () { return getVisibleSize().width; };
position.getVisibleHeight = function () { return getVisibleSize().height; };
position.getPageOffset = getPageOffset;
position.getPageOffsetX = function () { return getPageOffset().x; };
position.getPageOffsetY = function () { return getPageOffset().y; };

二、范例

    <script type="text/javascript">
document.body.onclick = function () {
alert(window.Position.getVisibleSize());
alert(window.Position.getPageOffset());
}
</script>

最新文章

  1. Selenium Webdriver下click失效问题解决
  2. cf378D(stl模拟)
  3. Linq学习之操作符
  4. DOS下快速删除文件
  5. Intel格式和AT&amp;T格式汇编区别
  6. 关于无光盘无u盘状态下该如何安装系统
  7. The Stern-Brocot Number System(排序二进制)
  8. Python笔记1-20151021
  9. 深入理解 JavaScript 中的 replace 方法(转)
  10. PHP 操作 进程时相关 信号的具体含义
  11. mybatis choose标签的使用
  12. spark-shell的Scala的一些方法详解
  13. 一个不错的多叉树, stl风格
  14. jenkins 构建到最后报权限的问题
  15. Pychram 在model中修改class属性值后更新到Navicat Premium中
  16. JavaScript —— 数组
  17. 2--linux命令--查看磁盘空间
  18. php判断文件夹是不是存在
  19. LibreOJ #6000. 「网络流 24 题」搭配飞行员 最大匹配
  20. 1086. Tree Traversals Again (25)-树的遍历

热门文章

  1. WCF账户密码认证
  2. configparser配置文件操作
  3. PD中将Comment 从Name复制值
  4. XE3随笔20:几个和当前路径相关的新函数
  5. Linux中的工作管理(Job Control )
  6. firefox的console log功能
  7. luogu p2330[SCOI05] 繁忙的都市——瓶颈生成树
  8. Unity3D安卓打包参数配置与兼容性的关系分析
  9. js-正则表达式的替换
  10. Swift基础语法(五)枚举、结构体与类的区别