0

I would like to exclude this JavaScript from functioning at a screen size smaller than 768px.

Do you know what I need to add to the code?

<script type="text/javascript">
    var timeOut;
    function scrollToTop() {
        if (document.body.scrollTop!=0 || document.documentElement.scrollTop!=0){
            window.scrollBy(0,-50);
            timeOut=setTimeout('scrollToTop()',10);
        }
        else{ 
            clearTimeout(timeOut);
        }
    }
</script>
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
DarrenLee
  • 137
  • 1
  • 11
  • possible duplicate of [Get the size of the screen, current web page and browser window](http://stackoverflow.com/questions/3437786/get-the-size-of-the-screen-current-web-page-and-browser-window) – Phil Aug 25 '15 at 09:58
  • Simply attach checking window width in some condition. – Girafa Aug 25 '15 at 09:59

1 Answers1

0

Add this to your method and you are good to go.

if(screen.width > 768) {
   //your method logic
}
Darshan Patel
  • 2,839
  • 2
  • 25
  • 38