浏览器对象模型介绍

前面学习了dom相关的操作和事件,本篇博客开始介绍浏览器对象模型

window对象是什么?

  1. 是js操作浏览器的接口
  2. 是一个全局对象

window常用事件

load vs DOMContentLoaded

load事件,The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets and images

window.onload = function(){
}

DOMContentLoaded事件 ,The DOMContentLoaded event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.

load 等到图片,css加载完触发
DOMContentLoaded,只要页面html解析完,不需要等css,图片加载完就会触发
DOMContentLoaded 触发会被load早

浏览器窗口变化事件

onresize属性可以用来获取或设置当前窗口的resize事件的事件处理函数

例如:rem布局的时候,监测到onresize变化时,修改html font-size

定时器

setTimeout var timerId = setTimeout(func|code, delay);
setInterval指定某个任务每隔一段时间就执行一次

使用定时器,要注意清除

setTimeout和setInterval函数,都返回一个整数值,表示计数器编号。将该整数传入clearTimeout和clearInterval函数,就可以取消对应的定时器。


思考:
w3c为什么会成为标准呢?
有了标准不一定非得遵守,重点是你要有足够的话语权。
也许有一天微信说,我要制定一个标准,那么它就成为标准了


很好的一篇博文https://tech.youzan.com/you-zan-qian-duan-zhi-liang-bao-zheng-ti-xi/

发布了370 篇原创文章 · 获赞 81 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/lineuman/article/details/103883359