我在页面上有几张图片,它们的图片底部有50px的标题。当它们加载时,它们从不透明度1开始,但我希望它们以0.5开始。原因是有一个hover
事件会将悬停时的不透明度设置为1,因此我希望它们从.5开始。使用jQuery,以不透明度加载div .5
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.fade').hover(function() {
$(this).stop().animate({"opacity": 1});
},function() {
$(this).stop().animate({"opacity": .5});
});
});
</script>
</head>
<body>
<div class="image_w_caption" style="float:left;margin:5px;">
<div class="image" style="width:250px;height:188px;background:url(images/image.jpg) no-repeat 0 0;">
</div>
<div class="fade" style="width:250px;height:188px;background:url(images/image_2.png) no-repeat 0 0;position:relative;top:-203;z-index:2;">
<p style="padding:150px 5px 0 5px;z-index:3;color:white;">text</p>
</div>
</div>
<div class="image_w_caption" style="float:left;margin:5px;">
<div class="image" style="width:250px;height:188px;background:url(images/image_2.jpg) no-repeat 0 0;">
</div>
<div class="fade" style="width:250px;height:188px;background:url(images/image_2.png) no-repeat 0 0;position:relative;top:-203;z-index:2;">
<p style="padding:150px 5px 0 5px;z-index:3;color:white;">more text</p>
</div>
</div>
</body>
</html>
小巧典雅的作品。谢谢。 – Adam