Created
January 10, 2013 17:36
-
-
Save davidicus/4504081 to your computer and use it in GitHub Desktop.
new API for adding an event listener and testing for media queries.
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
var mq = window.matchMedia("(min-width: 480px)"); | |
if (mq.matches) { | |
// window width is at least 480px | |
$('.slideOne').attr('src', 'img/slideOne.jpg'); | |
$('.slideTwo').attr('src', 'img/slideTwo.jpg'); | |
$('.slideThree').attr('src', 'img/slideThree.jpg'); | |
$('.slideFour').attr('src', 'img/slideFour.jpg'); | |
$('.slideFive').attr('src', 'img/slideFive.jpg'); | |
$('.slideSix').attr('src', 'img/slideSix.jpg'); | |
} | |
// media query event handler | |
if (matchMedia) { | |
var mq = window.matchMedia("(min-width: 480px)"); | |
//mq.addListener(WidthChange); | |
WidthChange(mq); | |
} | |
// media query change | |
function WidthChange(mq) { | |
if (mq.matches) { | |
// window width is at least 480px. do this code | |
} | |
else { | |
// window width is less than 480px. do this code | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.sitepoint.com/javascript-media-queries/