Skip to content

Instantly share code, notes, and snippets.

@bengourley
Created October 12, 2012 12:12
Show Gist options
  • Save bengourley/3878919 to your computer and use it in GitHub Desktop.
Save bengourley/3878919 to your computer and use it in GitHub Desktop.
Example break.js usage
// 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