Code to get the window size:
var pageWidth = window.innerWidth ,
var pageHeight = window.innerHeight;
if(typeof pageWidth != "number"){
if(document.compatMode == "number"){
pageWidth = document.documentElement.clientWidth ;
pageHeight = document.documentElement.clientHeight;
}else{
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
}
}
We first pay the values of window.innerWidth and window.innerHeight to pageWidth and pageHeight respectively. Then check whether the value saved in pageWidth is a value; if not, use document.compatMode to determine whether the page is in standard mode. If so, the values of document.documentElement.clientWidth and document.documentElement.clientHeight are used respectively. Otherwise, the values of document.body.clientWidth and document.body.clientHeight are used.
Code to get the window position:
var leftPos = (typeof window.screenLeft == "number") ? window.screenLeft : window.screenX;
var topPos = (typeof window.screenTop == "number") ? window.screenTop : window.screenY;
The purpose of these two examples is to obtain the position of the left and top sides of the window. First, use binary operators to determine whether the screenLeft attribute and screenTops attribute exist. If they exist (in IE, Safari, Opera and Chrome), then take The values of these two properties. If not present (in Firefox), the values of screenX and screenY are taken.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn