if (window.matchMedia('(max-width: 768px)').matches) { // do functionality on screens smaller than 768px }