I'm trying to black out the screen and center an image in the middle of the screen, above all other elements. What I have doesn't work (the image being centered part).
NOTE - I know there are probably plugins for this..but I'm trying to figure out how to do it and how it works.
var docHeight = $(document).height();
$("body").append("<div id='overlay'></div>");
$("#overlay").height(docHeight).css({
'opacity': 0.4,
'position': 'relative',
'top': 0,
'left': 0,
'color': 'white',
'background-color': 'black',
'width': '100%',
'z-index': 5000
});
$("#overlay").append("<div id='image-container'><img id='photo' src='" + $(this).attr('rel') + "' alt='image' /></div>");
$("#image-container").css("position", "absolute");
$("#image-container").css("top", Math.max(0, (($(window).height() - $("#image-container").outerHeight()) / 2) + $(window).scrollTop()) + "px");
$("#image-container").css("left", Math.max(0, (($(window).width() - $("#image-container").outerWidth()) / 2) + $(window).scrollLeft()) + "px");
CSS:
#image-container {
background: #FF0000;
z-index: 999999;
}
My image that I'm displaying is in the bottom right of the screen..not in the center. What am I doing wrong?