简体   繁体   中英

Exclude JavaScript from functioning at certain screen size

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>

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

if(screen.width > 768) {
   //your method logic
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM