Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackfalcon/3230392 to your computer and use it in GitHub Desktop.
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)
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();
});
.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;
}
<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