Skip to content

Instantly share code, notes, and snippets.

@nexik
Last active August 29, 2015 14:10
Show Gist options
  • Save nexik/0423f66405a596f99688 to your computer and use it in GitHub Desktop.
Save nexik/0423f66405a596f99688 to your computer and use it in GitHub Desktop.
jQuery WTF
$(function() {
var centerAbsolute = function () {
$('.absolute-center').css({
position:'absolute',
left: ($(window).width() - $('.absolute-center').outerWidth())/2,
top: ($(window).height() - $('.absolute-center').outerHeight())/2
});
}
centerAbsolute();
centerAbsolute();
});
Why Jquery? Why for first time $('.absolute-center').outerWidth() return the width of $(window).width()
Second time returns real one?
<div class="absolute-center" style="position: absolute; left: 0px; top: 52px;">
<div class="box white">dssd</div>
</div>
.box {
border-radius: 10px;
box-shadow: 0 0 15px rgba(22,22,23,0.15);
padding: 24px;
width: 300px;
height: 200px;
}
.box.white {
background: #fff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment