Skip to content

Instantly share code, notes, and snippets.

@marcnewport
Created September 13, 2018 01:31
Show Gist options
  • Select an option

  • Save marcnewport/9fdf79b4c59d54a7026ab4a9658bde16 to your computer and use it in GitHub Desktop.

Select an option

Save marcnewport/9fdf79b4c59d54a7026ab4a9658bde16 to your computer and use it in GitHub Desktop.

Revisions

  1. marcnewport created this gist Sep 13, 2018.
    15 changes: 15 additions & 0 deletions media-queries.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // media query event handler
    if (window.matchMedia) {
    const mq = window.matchMedia("(min-width: 500px)");
    mq.addListener(WidthChange);
    WidthChange(mq);
    }

    // media query change
    function WidthChange(mq) {
    if (mq.matches) {
    // window width is at least 500px
    } else {
    // window width is less than 500px
    }
    }