1

I want to execute this function only when screen is bigger than 1000px.

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
) 
barbsan
  • 3,418
  • 11
  • 21
  • 28
  • 1
    You can check for the width with `window.innerWidth` inside the function and proceed only if the width fulfills your requirements. – Łukasz Nojek Jul 10 '19 at 09:08
  • -Lukasz how do i do that – Failed Student Jul 10 '19 at 09:09
  • 1
    `var width = Math.max(document.documentElement.clientWidth, window.innerWidth, jQuery(window).width() || 0); if (width > 1000) { /* CODE HERE */ }` – GrafiCode Jul 10 '19 at 09:11
  • Possible duplicate of [Get the size of the screen, current web page and browser window](https://stackoverflow.com/questions/3437786/get-the-size-of-the-screen-current-web-page-and-browser-window) – GalAbra Jul 10 '19 at 09:15

2 Answers2

1
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
 ) 
}
Sandhya Nair
  • 157
  • 2
  • 9
0

you can use the method resize in the addEventListener