【发布时间】:2019-02-06 18:12:50
【问题描述】:
我有一个简单的画廊,当我单击图像(大小在 img 标签中定义)时,它应该在屏幕中心打开它并将其调整为原始尺寸或其他定义的尺寸。现在它只是使图像居中。 谢谢!
<style>
#img-cover {
position: absolute;
display:none;
top:0px;
left:0px;
width:100%;
height:100%;
background-color:black;
opacity:0.6;
z-index:9998;
}
#img-container {
position:fixed;
display:none;
top:50%;
left:50%;
margin-top:-50px;
margin-left:-100px;
z-index:9999;
}
</style>
<script>
$('.img').on('click', function (e) {
$('#img-cover').fadeIn();
var img = $(this);
$('#img-container').html(img.clone())
.css({
'margin-top': '-' + img.height() / 2 + 'px',
'margin-left': '-' + img.width() / 2 + 'px'
}).fadeIn();
});
$('#img-cover').on('click', function () {
$('#img-cover').fadeOut();
$('#img-container').fadeOut();
});
</script>
【问题讨论】: