Created
December 9, 2012 16:23
-
-
Save janily/4245878 to your computer and use it in GitHub Desktop.
position center
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
(function($){ | |
$.fn.extend ({ | |
center:function() { | |
return this.each(function(){ | |
var top = ($(window).height() - $(this).outerHeight())/2; | |
var left = ($(window).width() - $(this).outerWidth())/2; | |
$(this).css({position:'absolute',margin:0,top:(top>0 ? top:0)+'px',left:(left>0 ? left:0)+'px'}); | |
}); | |
} | |
}); | |
})(jQuery); | |
$('.center').center(); | |
$(window).resize(function(){ | |
$('.center').center(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment