惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
V
Vulnerabilities – Threatpost
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
B
Blog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
H
Hacker News: Front Page
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园_首页
D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
W
WeLiveSecurity
N
News and Events Feed by Topic
F
Fortinet All Blogs
PCI Perspectives
PCI Perspectives
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Recent Announcements
Recent Announcements
Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
Hacker News: Ask HN
Hacker News: Ask HN
爱范儿
爱范儿
腾讯CDC
Last Week in AI
Last Week in AI
月光博客
月光博客
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Help Net Security
Help Net Security
V
V2EX
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
H
Heimdal Security Blog
L
LINUX DO - 最新话题
GbyAI
GbyAI
The Hacker News
The Hacker News
罗磊的独立博客
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 【当耐特】
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V2EX - 技术
V2EX - 技术
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
O
OpenAI News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 川川哥哥

学习javascript-我的经验和建议(乱译) 一道有趣的javascript小题 javascript高性能编程笔记(个人自用) css3基础知识提纲 html5基础知识提纲 javascript语言精粹----笔记 利用C#编写一个简单的抓网页应用程序 对C#开发两个基本原则的深入讨论(转) ASP编程中15个非常有用的例子 - 川川哥哥 - 博客园 oracle9i使用OMS备份数据 如何清除掉归档日志文件? 雅虎公司C#笔试题[转] .NET 访问 Oracle 数据库相关 [转] 从ASP.NET1.1到2.0迁徙所遇到的 IIS无法显示ASP 最终幻想Ⅸ 最终幻想X小说 经典音乐country roads歌词 06年及以前韩国星际职业联赛及选手资料
javascript和jquery窗口定位方法对应表
川川哥哥 · 2012-08-29 · via 博客园 - 川川哥哥
位置

 javascript   

jquery

兼容性

窗口位置离屏幕左偏移

var leftPos = (typeof window.screenLeft == "number") ? window.screenLeft : window.screenX;   浏览器兼容性问题可能不准确,建议用moveTo

窗口位置离屏幕上偏移

var topPos = (typeof window.screenTop == "number") ? window.screenTop : window.screenY;  

浏览器兼容性问题可能不准确,建议用moveTo

窗口定位到某位置

window.moveTo(0,0)   Opera及IE7+默认禁用,且不适用于框架

窗口定位相对位置

window.moveBy(50,50)  

Opera及IE7+默认禁用,且不适用于框架

窗口调整大小1 window.resizeTo(100,100)    
窗口调用大小2 window.resizeTBy(100,50)    
页面视口大小         var pageWidth = window.innerWidth,
            pageHeight = window.innerHeight;   
        if (typeof pageWidth != "number"){
            if (document.compatMode == "CSS1Compat"){
                pageWidth= document.documentElement.clientWidth;
                pageHeight = document.documentElement.clientHeight;
            } else {
                pageWidth = document.body.clientWidth;
                pageHeight = document.body.clientHeight;
            }
        }
$(window).width()

$(window).height()

 
元素距页面顶部偏移量        function getElementTop(element){
            var actualTop = element.offsetTop;
            var current = element.offsetParent;
            while (current !== null){        
                actualTop += current.offsetTop;
                current = current.offsetParent;
            }
            return actualTop;
        }
$(element).offset().top js为递归计算,只对可见元素有效
元素距页面左侧偏移量         function getElementLeft(element){
            var actualLeft = element.offsetLeft;
            var current = element.offsetParent;
            while (current !== null){        
                actualLeft += current.offsetLeft;
                current = current.offsetParent;
            }
            return actualLeft;
        }

$(element).offset().left

js为递归计算,只对可见元素有效

元素在垂直方向上占用空间(含边框+内边距+滚动条) element.offsetHeight $(element).outerHeight(),  

元素在水平方向上占用空间(含边框+内边距+滚动条)

element.offsetWidth $(element).outerWidth(),  

元素在垂直方向上占用空间(不含边框,滚动条只含内边距)

element.clientHeight

$(element).height(),有区别,不含内边距

 

元素在水平方向上占用空间(不含边框,滚动条,只含内边距)

element.clientWidth

$(element).width(),有区别,不含内边距

 
在没有滚动条时,元素内容总高度

element.scrollHeight

jquery未找到对应方法

var docHeight = Math.max(document.documentElement.scrollHeight,
document.documentElement.clientHeight);

在没有滚动条时,元素内容总宽度

element.scrollWidth

jquery未找到对应方法 var docWidth = Math.max(document.documentElement.scrollWidth,
document.documentElement.clientWidth);
已被滚动卷去的上方像素

var top = document.body.scrollTop | document.documentElement.scrollTop;

$(document).scrollTop()

可以用此方法滚动到指定位置

已被滚动卷去的左方像素

var left = document.body.scrollLeft | document.documentElement.scrollLeft;

$(document).scrollLeft()

可以用此方法滚动到指定位置

兼容所有浏览器,

取得元素矩阵,返回

元素左上角坐标距

视窗口的

left,top,right,bottom值

        function getElementLeft(element){
            var actualLeft = element.offsetLeft;
            var current = element.offsetParent;
            while (current !== null){       
                actualLeft += current.offsetLeft;
                current = current.offsetParent;
            }
            return actualLeft;
        }
   
        function getElementTop(element){
            var actualTop = element.offsetTop;
            var current = element.offsetParent;
            while (current !== null){       
                actualTop += current. offsetTop;
                current = current.offsetParent;
            }
            return actualTop;
        }
   
    function getBoundingClientRect(element){
        var scrollTop = document.documentElement.scrollTop;
        var scrollLeft = document.documentElement.scrollLeft;
        if (element.getBoundingClientRect){
            if (typeof arguments.callee.offset != "number"){
                var temp = document.createElement("div");
                temp.style.cssText = "position:absolute;left:0;top:0;";
                document.body.appendChild(temp);
                arguments.callee.offset = -temp.getBoundingClientRect().top - scrollTop;
                document.body.removeChild(temp);
                temp = null;
            }
            var rect = element.getBoundingClientRect();
            var offset = arguments.callee.offset;
   
            return {
                left: rect.left + offset,
                right: rect.right + offset,
                top: rect.top + offset,
                bottom: rect.bottom + offset
            };
        } else {
            var actualLeft = getElementLeft(element);
            var actualTop = getElementTop(element);
           return {
                left: actualLeft - scrollLeft,
                right: actualLeft + element.offsetWidth - scrollLeft,
                top: actualTop - scrollTop,
                bottom: actualTop + element.offsetHeight - scrollTop
            }
        }
    }