There is a function, and you need to turn it off with a screen width of less than 1080 pixels, and turn on with a width of more than 1080 pixels. This code did not help me:

var screenWidth = document.documentElement.clientWidth; if (screenWidth <= 1080 ) { window.onscroll = false; } else if(screenWidth > 1080 { window.onscroll = true; } 

still tried to write such code to define the key variable

  var picInd = scrolled <= 1 && screenWidth >= 1080 ? 0 : scrolled > 8 && screenWidth >= 1080 ? 9 : scrolled; 

but also did not help.

    1 answer 1

    Read here: https://developer.mozilla.org/ru/docs/Web/API/Window/matchMedia about the function (or is it a method, just JS is so flexible that sometimes the methods are functions or window.matchMedia ) window.matchMedia

    Example:

     window.onload = function(){ window.onresize = function(){if(window.matchMedia("screen and (max-width: 2200px)").matches){ screenWidthUpdate = null; console.log("function deleted"); } } } var screenWidthUpdate = function(){ document.write("hello <hr/>"); } 

    • thanks a lot - Excess
    • one
      This will not work when resizing a window. - Pavel Mayorov
    • one
      @PavelMayorov Take it away minus. Wrap all this code in window.onresize = function(){} - Eugen Eray
    • @EugenEray does not make sense to wrap onload inside onresize. Minus will not remove until the answer is working. - Pavel Mayorov
    • @PavelMayorov Ok corrected. I sit on the phone - I can not see the snippet. - Eugen Eray