-
-
Save st3phan/1445179 to your computer and use it in GitHub Desktop.
Responsive JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onresize = function() { | |
responsiveLoad(); | |
} | |
window.onload = function() { | |
responsiveLoad(); | |
} | |
function responsiveLoad() { | |
console.log('resized'); | |
if (matchMedia) { | |
var mqs = window.matchMedia("(min-width: 951px)"); | |
mqs.addListener(WidthChangeToScreen); | |
WidthChangeToScreen(mqs); | |
var mqt = window.matchMedia("(min-width: 761px) and (max-width: 950px)"); | |
mqt.addListener(WidthChangeToTablet); | |
WidthChangeToTablet(mqt); | |
var mqm = window.matchMedia("(max-width: 760px)"); | |
mqm.addListener(WidthChangeToMobile); | |
WidthChangeToMobile(mqm); | |
} | |
} | |
function WidthChangeToScreen(mq) { | |
if (mq.matches) { | |
// screen is >= 951px wide | |
} | |
} | |
function WidthChangeToTablet(mq) { | |
if (mq.matches) { | |
// screen is >= 761px && <= 950px wide | |
} | |
} | |
function WidthChangeToMobile(mq) { | |
if (mq.matches) { | |
// screen is <= 760px wide | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment