【发布时间】:2013-12-12 15:58:07
【问题描述】:
我设计了一个包含许多小图像的页面,我喜欢点击小图像然后打开一个固定的 div 并显示我的大图像,它非常适合页面顶部的图像,但是当滚动下拉到页面底部时,它现在是干得好,什么是truble,你可以在这个页面看到它:http://www.3dcreate.ir/New3DCreate/Pages/Gallery/3DGallery/3dg_Chosen.php
HTML 代码:
<!-- This is Div of Large Image and Background Shade -->
<div class="BackgroudShade"></div>
<div class="DivOfImage"><img class="LargeImage"/></div>
CSS 代码:
.DivOfImage {
border: 8px solid #FFF;
color:#FFF;
background-color:#FFF;
border-radius:10px;
position:fixed;
}
JQuery 代码:
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();
})
【问题讨论】:
-
你为什么要重新发明轮子而不使用这些方便的灯箱之一?
-
css
position: fixed;不是你要找的吗?这样,即使您向下或向上滚动,图像也始终保持在给定的偏移量(中心)处。
标签: javascript jquery css html absolute