You need to center the object, the width of which varies depending on the browser window. Usually I used css with the top and left positions set to 50%, with a negative margin equal to half the width and height, but obviously this would not fit this need.
I thought my jQuery function would work ... but without bueno. Am I missing something in CSS?
Thank!
http://jsfiddle.net/danielredwood/EbkLg/2/
Here is CSS
#t {
width:25%;
height:25%;
background:red;
}
Javascript
$(window).resize(function(){
resizenow();
});
function resizenow() {
var browserwidth = $(window).width();
var browserheight = $(window).height();
$('#t').css('left', (browserwidth - $(this).width())/2).css('top', (browserheight - $(this).height())/2);
});
source
share