js media query

PHOTO EMBED

Tue Nov 01 2022 04:42:54 GMT+0000 (UTC)

Saved by @davidmchale #media #query #mediaquery

function mediaQuery(element, value) {
  let x = document.querySelector(element);

  x.forEach((item) => {
    if (window.matchMedia(`(max-width: ${value}px)`).matches) {
      item.classList.add('mobile');

    } else {
      item.classList.remove('mobile');
    }

  })

  return x;

}

// add class mobile to the element class hero on the screensize 600px
mediaQuery(".hero", 600);
content_copyCOPY