我设计了一个包含许多小图片的页面,我喜欢点击小图片然后打开一个固定的 div 并显示我的大图片,它非常适合页面上方的图片但是当滚动下拉到页面底部时它现在好好工作,什么是真正的
function LoadShowDiv () {
$('.BackgroudShade').slideDown(800); // shade of background will be visible
$(".DivOfImage").show(); // Div of Large Image will be visible
// When Image loaded successful then set width,height and top,left of Large Image Div
// but i want set top,left when screen is scroll down to bottom of page
// then show Div at middle of screen in every time
$('.LargeImage').load(function() {
$('.DivOfImage').width($('.LargeImage').width());
$('.DivOfImage').height($('.LargeImage').height());
var LeftPostion = (WidthOfScreen - $('.LargeImage').width()) / 2;
var TopPostion = (HeightOfScreen - $('.LargeImage').height()) / 2;
$(".DivOfImage").offset({ top: TopPostion, left: LeftPostion});
$('.LargeImage').show(1000);
})
}
$('#SmallImage').click(function(){
$('.LargeImage').attr('src','LargeImage.jpg');
LoadShowDiv();
})
.DivOfImage {
border: 8px solid #FFF;
color:#FFF;
background-color:#FFF;
border-radius:10px;
position:fixed;
}
HTML 代码:
<!-- This is Div of small Image -->
<div class="Image_DIV" id="Image20">
<table>
<tr><td class="Image"><img src="Chosen/Small/20.jpg"/></td></tr>
<tr>
<td class="ImageDescribe"></td></tr>
</table>
</div>
<!-- This is Div of Large Image and Background Shade -->
<div class="BackgroudShade"></div>
<div class="DivOfImage"><img class="LargeImage"/></div>
最佳答案
从你的 css
中删除 position:fixed;
只使用 position:absolute;
就像,
.DivOfImage {
border: 8px solid #FFF;
color:#FFF;
background-color:#FFF;
border-radius:10px;
position:absolute;// use absolute only
}
在 Absolute
之后使用 Fixed
会覆盖您的 position 属性
并且不会使其成为 absolute
关于javascript - 如何在屏幕中间显示div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20537225/