Last active
December 17, 2015 06:38
-
-
Save ziluo/5566527 to your computer and use it in GitHub Desktop.
文档坐标和视口坐标
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//以一个对象的x和y属性的方式返回滚动条的偏移量 | |
function(w){ | |
var w = w || window; | |
if(w.pageXOffset != null) return {x: x.pageXOffset, y: w.pageYOffset}; | |
var d = w.document; | |
if(document.compatMode == "CSS1Compat"){ | |
return {x:d.documentElement.scrollLeft,y:d.documentElement.scrollTop}; | |
}else{ | |
return {x:d.body.scrllLeft,y:d.body.scrollTop}; | |
} | |
} | |
//作为一个对象的w和h属性的方式返回视口的尺寸 | |
function(w){ | |
var w = w || window; | |
if(w.innerWidth != null) return {x: x.innerWidth, y: w.innerHeight}; | |
var d = w.document; | |
if(document.compatMode == "CSS1Compat"){ | |
return {x:d.documentElement.clientWidth,y:d.documentElement.clientHeight}; | |
}else{ | |
return {x:d.body.clientWidth,y:d.body.clientHeight}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment