Ciao a tutti, sto sviluppando un light box ma sto avendo problemi con il calcolo delle dimensioni, l'immagine si dovrebbe trovare al centro dello schermo ma non capisco dove sbaglio...
<style>
.darkContent{
position: fixed;
background-color: #FFFFFF;
border: 5px solid #000000;
padding: 8px;
overflow: hidden;
color: #333;
font-family: arial;
}
.darkCover{
position: fixed;
left: 0px;
top: 0px;
z-index: 100;
background-color: #000000;
opacity: 0;
width: 100%;
height: 100%;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$(".darkBox").each(function(){
var div = $($(this).attr("href"));
div.hide();
$(this).click(function(){
darkBox(div);
});
});
});
function darkBox(div){
(div.attr("width")) ? w = div.attr("width") : w = div.width();
(div.attr("height")) ? h = div.attr("height") : h = div.height();
var box = $("<div></div>").addClass("darkCover");
$("body").prepend(box);
box.fadeTo("fast",0.8);
var contentBox = $("<div></div>").html(div.html());
contentBox.addClass("darkContent");
var open = "center";
switch(open){
case "center":
default:
x = $(window).width()/2;
y = $(window).height()/2;
startW = h-y/2;
startH = w-x/2;
endTop = y - h/2;
endLeft = x - w/2;
break;
}
alert(startW);
contentBox.css({"left":x+"px","top":y+"px","z-index":"200"});
contentBox.css({"width":startW+"px","height":startH+"px"});
$("body").prepend(contentBox);
contentBox.animate({
opacity:1,
width:w+"px",
height:h+"px",
top:endTop+"px",
left:endLeft+"px"
},1000,"easeOutExpo");
box.click(function(){
box.fadeOut();
contentBox.fadeOut();
});
}
</script>
<a href="#login">Box</a>
<div id="login" height="796px" width="625px">
<img src="4d7336d5da630.jpg">
</div>