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