当前位置:网站首页>window对象的常见事件
window对象的常见事件
2022-07-27 00:43:00 【抱抱旋旋子】
一.窗口页面加载事件

window.onload是窗口(页面)加载事件,当文档内容完全加载完成会触发该事件(包括图像、脚本文件、CSS文件等),就调用的处理函数。
注意∶
1.有了window.onload就可以把JS代码写到页面元素的上方,因为onload是等页面内容全部加载完毕,再去执行处理函数。
2. window.onload传统注册事件方式只能写一次,如果有多个,会以最后一个window.onload为准。
3.如果使用addEventListener则没有限制
DOMContentLoaded事件触发时,仅当DOM加载完成,不包括样式表,图片,flash等等。le9以上才支持
如果页面的图片很多的话,从用户访问到onload触发可能需要较长的时间交互效果就不能实现,必然影响用户的体验,此时用DOMContentLoaded事件比较合适。
load 等页面内容全部加载完毕,包含页面dom元素,图片,f1ash, css等等
DOMContentLoaded是DOM加载完毕,不包含图片falsh css 等就可以执行,加载速度比load更快一些

二.调整窗口大小事件

window.onresize是调整窗口大小加载事件,当触发时就调用的处理函数。
注意∶
1.只要窗口大小发生像素变化,就会触发这个事件。
⒉我们经常利用这个事件完成响应式布局。window.innerWidth当前屏幕的宽度

边栏推荐
- Debezium series: the binlog file cannot be recovered after the record is hung from the library server, and the task is switched to the main library to ensure that the data is not lost
- 商城小程序项目完整源码(微信小程序)
- 毕业2年转行软件测试获得12K+,不考研月薪过万的梦想实现了
- Interview shock 68: why does TCP need three handshakes?
- 全网最全的软件测试基础知识整理(新手入门必学)
- Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
- ZJCTF_login
- [栈和队列简单题] LeetCode 232. 用栈实现队列,225. 用队列实现栈
- {“errcode“:44001,“errmsg“:“empty media data, hint: [1655962096234893527769663], from ip: 222.72.xxx.
- 关于url编解码应该选用的函数
猜你喜欢

"Software testing" packaging resume directly improves the pass rate from these points

Baidu cloud face recognition

对象创建的流程分析

毕业2年转行软件测试获得12K+,不考研月薪过万的梦想实现了

Getlocation:fail the API need to be declared in the requiredprivateinfo field in app.json

Plato Farm全新玩法,套利ePLATO稳获超高收益

Inftnews | ggac and China Aerospace ases exclusively produce "China 2065 Collection Edition"

制作ppt时间轴

What is a process?

Pyqt5 use pyqtgraph to draw dynamic scatter chart
随机推荐
[动态规划简单题] LeetCode 53. 最大子数组和
Which securities firm is safer to open an account and buy REITs funds?
[paper]PointLaneNet论文浅析
基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
Plato Farm全新玩法,套利ePLATO稳获超高收益
[二分查找简单题] LeetCode 35. 搜索插入位置,69. x 的平方根,367. 有效的完全平方数,441. 排列硬币
数据库读写分离和分库分表
[SQL simple question] leetcode 627. change gender
Okaleido Tiger 7.27日登录Binance NFT,首轮已获不俗成绩
Ansible series: do not collect host information gather_ facts: False
OD-Paper【3】:Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
time模块: 时间戳、结构化时间、格式化时间的获取与相互转化
全网最全的软件测试基础知识整理(新手入门必学)
B-树的应用以及添加和删除操作
Integrated water conservancy video monitoring station telemetry terminal video image water level water quality water quantity flow velocity monitoring
CS224W fall 课程 ---- 1.1 why Graphs ?
机器学习【Matplotlib】
[redis] quick start
Leetcode- > binary search clock in
MarqueeView实现滑动展示效果