Created
September 13, 2013 10:26
-
-
Save lutzissler/6549000 to your computer and use it in GitHub Desktop.
Watch responsive layout changes with the help of an additional element in the body and an appropriate color setting.
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
@media screen and (min-width: ...) { | |
// Adjust the breakpoint identifier so that jQuery knows about it | |
#bp { | |
color: rgb(1, 1, 1); | |
} | |
} | |
@media screen and (min-width: ...) { | |
// Adjust the breakpoint identifier so that jQuery knows about it | |
#bp { | |
color: rgb(2, 2, 2); | |
} | |
} | |
... |
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
// Watch responsive breakpoints | |
var bp = false; | |
$(window) | |
.on("resize", function () { | |
var identifier = $("#bp"), | |
new_bp = false; | |
if (identifier.length == 0) { | |
$("body").append('<div id="bp"/>'); | |
identifier = $("#bp"); | |
} | |
var color = identifier.css("color"); | |
for (var i = 0; i <= 9; i++) { | |
var rgb = 'rgb(' + i + ', ' + i + ', ' + i + ')'; | |
if (color == rgb) { | |
new_bp = i; | |
} | |
} | |
if (new_bp != bp) { | |
$(window).trigger("layoutchanged", { new_bp: new_bp, old_bp: bp }); | |
bp = new_bp; | |
} | |
}) | |
.trigger("resize"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment