Skip to content

Determine if the document matches the media query string in JavaScript.

License

Notifications You must be signed in to change notification settings

bzaman/JavaScript-Media-Queries

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

JavaScript-Media-Queries

Determine if the document matches the media query string in JavaScript.

// create function
function mediaQuery(minMaxWidth = 'min', measure = 768, callBack) {
  var mq = window.matchMedia(`(${minMaxWidth}-width: ${measure}px)`);
  function mediaQueryChange(e) {
    if (e.matches) {
      callBack();
    }
  };
  mq.addListener(mediaQueryChange)
  mediaQueryChange(mq)
};

// Call and do your stuff...

 mediaQuery('max', 767, function(){
   console.log('max test...');
 });

 mediaQuery('min', 900, function(){
   console.log('min test...');
 });

About

Determine if the document matches the media query string in JavaScript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published