Mine is: <!DOCTYPE html> Blog Garden: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> For more information about HTML document types, please visit: http://i.wanz.im/2010/05/28/why_doctype_html/ After checking, I found that JS was getting the visible size of the current page, which was different from the scroll position of the page! When the HTML doctype is not added to the HTML, it defaults to a special mode!
analyze: Total page width: document.body.scrollWidth; Copy code The code is as follows:function getSize() { var obj = new Object(); obj.allWidth = document.body.scrollWidth; obj.allHeight = document.body.scrollHeight; if (-[1, ]) { //non-IE obj.top = document.body.scrollTop; obj.left = document.body.scrollLeft; if (document.compatMode === 'CSS1Compat') { obj.width = document.documentElement.clientWidth; obj.height = document.documentElement.clientHeight; } else { obj.width = document.body.clientWidth; obj.height = document.body.clientHeight; } } else { if (document.compatMode === 'CSS1Compat') { obj.width = document.documentElement.clientWidth; obj.height = document.documentElement.clientHeight; obj.top = document.documentElement.scrollTop; obj.left = document.documentElement.scrollLeft; } else { obj.width = document.body.clientWidth; obj.height = document.body.clientHeight; obj.top = document.body.scrollTop; obj.left = document.body.scrollLeft; } } alert(obj.top); alert(obj.left); alert(obj.width); alert(obj.height); return obj; } Note: The HTML document type of the blog garden homepage is found to be: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Why is it different from the essay display page? Welcome to reprint, please indicate: Reprinted from [ http://www.cnblogs.com/zjfree/ ] |
<<: Tips on HTML formatting and long files for web design
>>: How to set up cross-domain access in IIS web.config
environment: 1. Windows Server 2016 Datacenter 64...
Table of contents 1. Demand 2. Implementation 3. ...
Table of contents Preface: System Requirements: I...
Table of contents 1. MySQL compilation and instal...
Zen Coding It is a text editor plugin. In a text ...
[LeetCode] 182.Duplicate Emails Write a SQL query...
After reinstalling the system today, I reinstalle...
In actual Web development, inserting images, incl...
1. First, create a hello-world.cpp file The progr...
Preface <br />In the previous article "...
Preface Under Linux, compilation and linking requ...
Table of contents 1. Template tag in HTML5 2. Pro...
Programmers must deal with MySQL a lot, and it ca...
Installation environment: CentOS7 64-bit MINI ver...
Table of contents 1. Define object methods 2. Def...