当一个小图像被点击并显示一个大图像时,我试图获得暗淡的效果,
<div id="main_content">
<div id="press_page">
<div id="press_images">
<img id="s1" class="small" src="images/press/small/press1.jpg" />
<img id="s2" class="small" src="images/press/small/press2.jpg" />
<img id="b1" class="big" src="images/press/big/press1.jpg" />
</div>
</div>
</div>
$(function() {
$('#s1').click(function() {
$('#main_wrapper').animate({opacity:0.1},1000);
$('img.big').animate({opacity:1},1000).css('display','block');
});
});问题是大图片出现了,然后页面变暗了,包括大图片,但我需要让页面变暗,然后大图片以不透明度1出现,而其他一切都是暗的。
任何帮助都将不胜感激。
谢谢
发布于 2009-11-25 22:54:14
我认为更好的方法是创建一个覆盖图。类似于:
#overlay {
position: absolute;
display: none;
z-index:100;
top: 0px;
left: 0px;
height:100%;
width:100%;
background: #000;
}将其设置为从不透明度0到0.8或其他值,然后显示其上方的大图像。
img.big {
position: absolute;
z-index: 101;
top:50%;
left:50%;
margin-top: - (height of image / 2)
margin-left: - (width of image / 2)
}关于如何将其与一些jQuery交互联系起来,有大量的good tutorials。
发布于 2009-11-25 22:47:54
将大图的动画放在调光器的animate函数的回调中,这样在调光发生后才会发生。
$('#main_wrapper').animate({opacity:0.1}, 1000, function () {
$('img.big').animate({opacity:1},1000).css('display','block');
});发布于 2009-11-25 22:54:42
AFAIK,您不能使父DOM元素具有一定的不透明度,而不使其子元素也具有该不透明度。
您的代码当前将父div的opactiy设置为10%,然后将图像不透明度设置为10%的100% -即。和其他图像一样。
我认为一个简单的解决方案是在类上执行选择。div中的其他图像都有一个名为"small“的类,所以为什么不简单地写:
$(document).ready(function(){
$('#s1').click(function() {
$('.small').animate({opacity:0.1},1000);
});
});https://stackoverflow.com/questions/1797306
复制相似问题