Created
October 12, 2012 12:12
-
-
Save bengourley/3878919 to your computer and use it in GitHub Desktop.
Example break.js usage
This file contains hidden or 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
// Make breakpoints first | |
window.addBreakpoint('medium', '(min-width: 600px)') | |
window.addBreakpoint('large', '(min-width: 900px)') | |
// Test the initial window width | |
if (window.innerWidth < 600) { | |
// load mobile imgs | |
} else if (window.innerWidth < 900) { | |
// load tablet images | |
} else { | |
// load desktop images | |
} | |
// Then listen for changes | |
$(window) | |
.on('medium.exit', function () { | |
// Now < 600 so swap for mobile imgs | |
}) | |
.on('medium.enter', function () { | |
// > 600 so swap for tablet imgs | |
}) | |
.on('large.exit', function () { | |
// < 900 so swap for tablet imgs | |
}) | |
.on('large.enter', function () { | |
// > 900 so swap for desktop imgs | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment