You could wrap your script in an if statement that checks how wide the screen is like this:
if(window.innerWidth > 568){
...execute script
}
However, that will only execute once, so what if you resize your browser window? You could have an event listener that executes your script whenever you resize the browser.
window.addEventListener('resize', function(){
if(window.innerWidth > 568){
...execute script
}
});