最近几天部署代理池的时候,用Python写了requests请求测试IP地址检测连通性的脚本。但是发现了一个问题,requests.get带代理请求有时候请求不通。我初步认为代理的问题,但是之后我用了
顺晟科技
2021-08-29 10:35:49
103
window.matchMedia
方法返回一个 MediaQueryList
对象。window.matchMedia
接受 媒体查询字符串 作为参数。
const mql1 = window.matchMedia('(max-width: 600px)');
const mql2 = window.matchMedia('(min-width: 400px) and (max-width: 800px)');
返回一个 boolean 值。判断当前的 document 是否匹配 媒体查询字符串。匹配返回 true。否则返回 false。
const mql = window.matchMedia('(max-width: 600px)');
mql.matches
不匹配 媒体查询字符串
匹配 媒体查询字符串
返回 媒体查询字符串
const mql = window.matchMedia('(min-width: 400px) and (max-width: 800px)');
// "(min-width: 400px) and (max-width: 800px)"
mql.media
为 MediaQueryList 对象添加一个监听器。
const mql = window.matchMedia('(min-width: 400px) and (max-width: 800px)');
const callback = function () {
if (mql.matches) {
console.log('匹配')
} else {
console.log('不匹配')
}
}
mql.addListener(callback)
只有当 mql。matches 发生变化的时候, callback 才会调用。如果想要一开始就执行逻辑。可以手动的调用一遍 callback
const mql = window.matchMedia('(min-width: 400px) and (max-width: 800px)');
const callback = function () {
if (mql.matches) {
console.log('匹配')
} else {
console.log('不匹配')
}
}
callback()
mql.addListener(callback)
用于移除监听器
const mql = window.matchMedia('(min-width: 400px) and (max-width: 800px)');
const callback = function () {
if (mql.matches) {
console.log('匹配')
} else {
console.log('不匹配')
}
}
mql.addListener(callback)
mql.removeListener(callback)
19
2022-10
14
2022-09
14
2022-09
13
2022-09
13
2022-09
13
2022-09