Forked from jordanmoore/RWD Screen Width Indicator (em version)
Created
August 1, 2012 20:24
-
-
Save blackfalcon/3230392 to your computer and use it in GitHub Desktop.
Current screen width indicator in EMs (useful for knowing when to add breakpoints when resizing browser window)
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
function showEms() { | |
var windowWidth = $(window).width(); | |
var bodyFontSize = $('body').css('font-size'); | |
var bodyFontSizeWithoutPx = parseInt(bodyFontSize); | |
var emValue = windowWidth/bodyFontSizeWithoutPx; | |
$('.screen-width').text(' ' + emValue + 'em'); | |
} | |
// or you could do | |
var showEms = function(){ | |
var em_value = $(window).width() / parseInt($('body').css('font-size')); | |
$('.screen-width').text(' ' + em_value + 'em'); | |
return true; | |
}; | |
// call the function | |
$(document).ready(function() { | |
showEms(); | |
}); | |
$(window).resize(function() { | |
showEms(); | |
}); |
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
.emBox { | |
position: fixed; | |
padding: 0.41667em 0.83333em; | |
background: #474747; | |
color: white; | |
font-weight: bold; | |
font-size: 1em; | |
bottom: 0; | |
left: 0; | |
border-radius: 0 0.41667em 0 0; | |
} | |
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
<div class="emBox"> | |
<span class="screen-width">0</span> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment