当前位置:网站首页>Common operations of BOM and compatible writing methods for obtaining page / window height, width and scrolling
Common operations of BOM and compatible writing methods for obtaining page / window height, width and scrolling
2022-07-27 09:09:00 【M78_ Domestic 007】
brief introduction :
BOM yes Browse Object Model, Browser object model for short .
Document object model of browser , There is no unified standard , Don't like DOM( Document object model ) Yes, there is W3C The provision made by the alliance is right HTML Interface for document operation ;BOM Although it is not a standard interface , But the functions of this interface provided by browser manufacturers are roughly the same .
window The object is BOM The top floor of ( The core ) object , All objects extend through it .
window Under the Several function objects (window Properties of ) Yes :navigatior,screen,document,history,location
1、navigator object
Its properties :
appCodeName Return the code name of the browser ;
appName Return to the name of the browser ;
appVersion Return the platform and version information of the browser ;
cookieEnabled Return to indicate if... Is enabled in the browser cookie Boolean value ;
platform Return to the operating system platform where the browser is running ;
userAgent Returns... Sent by the client to the server user-agent The value of the head .
2、screen object
Its properties :
availHeight Back to the height of the screen ( barring Windows The task bar );
availWidth Back to the width of the screen ( barring Windows The task bar );
height Returns the total height of the screen ;
width Returns the total width of the screen ;
pixelDepth Return to the color resolution of the screen ( The number of bits per pixel ).
3、document object
We have studied it alone before document object , I won't go into that .
4、history object
Its properties :
length Return the number of URLs in the access history list ;
back() load history The previous one in the list URL;
forward() load history Next... In the list URL;
go(number|url) load history A specific page in the list // Negative numbers go back , Forward in positive numbers
5、location object
Its properties :
hash Return to one URL Anchor part of //192.168.1.102:8081?name=jack&pwd=123#page1;
host Return to one URL The host name and port of ;
hostname return URL The host name ;
href Return to the complete URL ;
pathname Back to URL Pathname ;
port Return to one URL The port number used by the server ;
protocol Return to one URL agreement ;
search Return to one URL The query part of .
Method :
assign(url) Load a new document ;
reload() Reload the current document ;
replace(url) Replace the current document with a new document .
window Other properties of :
closed Whether the return window has been closed .
innerHeight Returns the height of the document display area of the window
innerWidth Returns the width of the document display area of the window
outerHeight Returns the external height of the window , Contains toolbar and scroll bar
outerWidth Returns the external width of the window , Contains toolbar and scroll bar
screenLeft Returns the relative to the screen window x coordinate
screenTop Returns the relative to the screen window y coordinate
screenX Returns the relative to the screen window x coordinate
screenY Returns the relative to the screen window y coordinate
onload Specify when all configurations are loaded ( Picture exception ) Called function .
pageXOffset Return to the top left corner of the current page relative to the window display area X Location (body Horizontal rolling distance )
pageYOffset Return to the top left corner of the current page relative to the window display area Y Location (body Vertical rolling distance )
window Methods :
alert() Display a warning box with a message and a confirm button .
close() Close the browser window .
confirm() Displays a dialog box with a message and a confirm and Cancel buttons .
open(url, Open mode , New window configuration ,BOOL) Open a new browser window //4 All parameters are optional ( Usually fill in the first parameter ) //url: New window address Open mode :blank( Default ),parent,self,top To configure ( Various ): General default BOOL: The new window is in the history , Do you want to replace print() Print the contents of the current window .
prompt(tishi,value) Displays a dialog box that prompts for user input .
scrollBy() Scrolls content according to the specified pixel value ( The premise is that you have a scroll bar : Enough content )
scrollTo() Scroll content to specified coordinates .( The premise is that you have a scroll bar : Enough content )
setInterval(callback,times) According to the specified period ( In milliseconds ) To call a function
setTimeout(callback,times) Call the function after the specified millisecond count.
clearInterval() Cancel from setInterval() Set up timeout.
clearTimeout() Cancel from setTimeout() Method set timeout.
5.navigator
Let the window scroll to the specified position
1. Roll to the specified coordinates , The premise is that the page is long enough , Be able to scroll
window.scrollTo(x,y);
window.scroll(x,y);
scrollBy(x,y);
The functions of the first two methods are similar , The usage is to x,y Coordinates the incoming , Scroll to the specified position . and scrollBy() It will accumulate on the basis of previous data .
2.el.scrollIntoView()
Scroll to the specified element visible , The bottom of the calling element will try to be flush with the top of the viewport , Not necessarily. The main thing is whether you can roll How far can you roll el.scrollIntoView(true) The default is true, Align the element with the top edge of the viewport ; If you pass parameters false, Align the lower edge of the element with the lower edge of the viewport ;
Some methods have compatibility problems , Adopt compatibility writing method to solve .
Page scrolling distance
window.pageXOffset/window.pageYOffset (x Axis and y Axis ),IE8 And IE8 The following are not compatible
Compatible with :
document.body.scrollLeft/scrollTop
document.documentElement.scrollLeft/scrollTop
combined , Compatible writing :
sY=window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop
sX=window.pageXOffset||document.body.scrollLeft||document.documentElement.scrollLeftThe size of the visible area of the window
window.innerWidth/window.innerHeight// bom operation ,IE8 And IE8 The following are not compatible ;
document.documentElement.clientWidth/clientHeight// In standard mode (<!DOCTYPE html>, Rendering mode ), Any browser is compatible ;
document.body.clientWidth/clientHeight// Suitable for weird / Browser in hybrid mode ;
document.compatMode// Distinguish between standard mode and not .(BackCompat: Standard compatibility mode off .CSS1Compat: Standard compatibility mode on )
Compatible writing :
let cWidth,cHeight;
if (document.compatMode == "BackCompat") {
cWidth = window.innerWidth||document.body.clientWidth;
cHeight =window.innerHeight||document.body.clientHeight;
} else {
//document.compatMode == "CSS1Compat"
cWidth = window.innerWidth||document.documentElement.clientWidth;
cHeight = window.innerHeight||document.documentElement.clientHeight;
}Geometric dimensions of elements
el.getBoundingClientRect();
This method returns an object , There are... In the object left,top,right,bottom,height,width attribute .
left and top Represents the top left corner of the element X and Y coordinate ,right and bottom Represents the lower right corner of the element X and Y coordinate , There are properties in the returned object x,y, Indicates that the left vertex of the element is relative to the page body Distance of left vertex .
边栏推荐
- Ztree custom title attribute
- 如何注册码云账号
- CUDA Programming -03: thread level
- Pytorch custom CUDA operator tutorial and runtime analysis
- 【微服务~Sentinel】Sentinel之dashboard控制面板
- QDoubleValidator不生效问题解决办法
- Explanation of common basic controls for C # form application (suitable for Mengxin)
- Hangzhou E-Commerce Research Institute released an explanation of the new term "digital existence"
- Aruba learning notes 10 security authentication portal authentication (web page configuration)
- Replace restricts the text box to regular expressions of numbers, numbers, letters, etc
猜你喜欢

对 int 变量赋值的操作是原子的吗?

8 kinds of visual transformer finishing (Part 1)

Pytorch custom CUDA operator tutorial and runtime analysis

pollFirst(),pollLast(),peekFirst(),peekLast()

Explain cache consistency and memory barrier

Cross domain and processing cross domain
![[I2C reading mpu6050 of Renesas ra6m4 development board]](/img/1b/c991dd0d798edbb7410a1e16f3a323.png)
[I2C reading mpu6050 of Renesas ra6m4 development board]

Flex layout (actual Xiaomi official website)

Activation functions commonly used in deep learning

音乐体验天花板!14个网易云音乐的情感化设计细节
随机推荐
8 kinds of visual transformer finishing (Part 2)
C# 窗体应用常用基础控件讲解(适合萌新)
vscod
Babbitt | yuan universe daily must read: Guangzhou Nansha released the "Yuan universe nine" measures, and the platform can obtain up to 200million yuan of financial support
Solve the problem of Chinese garbled code on the jupyter console
BOM的常用操作和有关获取页面/窗口高度、宽度及滚动的兼容性写法
Pyqt5 rapid development and practice 4.1 qmainwindow
Is the operation of assigning values to int variables atomic?
基于restful页面数据交互
linux安装和远程连接mysql记录
async/await的执行顺序以及宏任务和微任务
Deep understanding of Kalman filter (2): one dimensional Kalman filter
新年小目标!代码更规范!
CUDA programming-04: CUDA memory model
MySQL basic knowledge learning (I)
Can "Gulangyu yuancosmos" become an "upgraded sample" of China's cultural tourism industry
JS detects whether the client software is installed
BEVFormer: Learning Bird’s-Eye-View Representation from Multi-Camera Images via Spatiotemporal Trans
Understand various IOU loss functions in target detection
Matlab drawing skills and examples: stackedplot