:root
var(--xx)
CSS 变量filter:blur()
change
, mousemove
NodeList 并不能使用 Array的方法
const inputs = document.querySelectorAll('.controls input'); //NodeList
如何将NodeList转化为Array
通过Array.prototye.slice 可以将NodeList 转化为数组,并可以用数组的方法了.
var slice = Array.prototype.slice;
var dom = slice.call(document.querySelectorAll(selector))
dataset
Example
<div id="user" data-id="1234567890" data-user="johndoe" data-date-of-birth>John Doe</div>
const el = document.querySelector('#user');
// el.id == 'user'
// el.dataset.id === '1234567890'
// el.dataset.user === 'johndoe'
// el.dataset.dateOfBirth === ''
CSS 自定义属性,可以被重复使用。 用法 --*
:root
:root
匹配文档的根元素,也就是<hmtl>
标签
Example
//全局CSS变量
:root {
--color: #fff;
}
img {
background: var(--base);
}
document.documentElement
代表文档根元素
document.documentElement.style.setProperty('--base', '#fff');
const suffix = this.dataset.sizing || '';