Javascript 仅当屏幕大于时,如何执行此功能
我只想在屏幕大于1000px时执行此功能Javascript 仅当屏幕大于时,如何执行此功能,javascript,Javascript,我只想在屏幕大于1000px时执行此功能 window.addEventListener( 'scroll', event => { const nav = document.querySelector('.module') if (250 <= window.scrollY) { nav.classList.add('flyin') nav.classList.remove('module') }
window.addEventListener(
'scroll',
event => {
const nav = document.querySelector('.module')
if (250 <= window.scrollY) {
nav.classList.add('flyin')
nav.classList.remove('module')
}
else nav.classList.List.add('none')
},
false
)
window.addEventListener(
“卷轴”,
事件=>{
const nav=document.querySelector(“.module”)
如果(250<代码>如果(window.innerWidth>1000){
window.addEventListener(
“卷轴”,
事件=>{
const nav=document.querySelector(“.module”)
如果(250您可以使用addEventListener中的resize方法,您可以在函数中使用window.innerWidth
检查宽度,并且仅当宽度满足您的要求时才继续。-Lukasz我如何做var width=Math.max(document.documentElement.clientWidth,window.innerWidth,jQuery(window.width()| 0);如果(宽度>1000){/*CODE HERE*/}
变量名不具有描述性且仅使用一次时,为什么var w
可能重复?
if (window.innerWidth > 1000) {
window.addEventListener(
'scroll',
event => {
const nav = document.querySelector('.module')
if (250 <= window.scrollY) {
nav.classList.add('flyin')
nav.classList.remove('module')
}
else nav.classList.List.add('none')
},
false
)
}