【发布时间】:2011-11-12 04:14:10
【问题描述】:
我在一个页面上有几张图片,它们的标题覆盖了图片底部 50 像素。当它们加载时,它们以不透明度 1 开始,但我希望它们以 0.5 开始。原因是有一个 hover 事件在悬停时将不透明度设置为 1,所以我希望它们从 0.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>
【问题讨论】:
标签: jquery jquery-animate opacity