Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created July 26, 2023 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocodesupplyco/699bc6dca2d2e7897469a968d149bba4 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/699bc6dca2d2e7897469a968d149bba4 to your computer and use it in GitHub Desktop.
Only run some javascript when the browser is 767px or smaller.
function responsiveScript() {
// only run script below 767 px screen width
if (window.innerWidth <= 767) {
// do something awesome on mobile only here
}
}
// run script on page load
responsiveScript();
// run script on window resize
window.addEventListener("resize", responsiveScript);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment