时间:2021-07-01 10:21:17 帮助过:18人阅读
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery照片伸缩效果</title>
</head>
<!-- The Style -->
<style type="text/css">
*{
margin: 0;
padding: 0;
}
body{
font-family: "Myriad Pro", "Trebuchet MS", Helvetica, sans-serif;
font-size: 12px;
color: #fff;
}
#col {
width: 600px;
height:400px;
margin: 20px auto 0px auto;
border: 1px solid #2D353F;
}
.pic {
width: 200px;
height: 200px;
margin: 0px;
overflow: hidden;/*这边定义了overflow为hidden*/
position: relative;/*这边定义了position为relative,这其实是为了下面的img的position可以依照pic定位*/
float: left;
}
/*图片的原始大小是500*333左右*/
/*这里并没有对width宽度做文章,是对height高度做文章的*/
.pic a img {
height: 500px;
border: none;
position: absolute; /*正因为父标签定义了position,这边img定义position才有定位依据,要不然就是对于整个浏览器进行定位*/
top: -66.5px;
left: -150px;
opacity: 0.5;
-moz-opacity: 0.5;
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50);/*这边为了兼容浏览器,和opacity属性的作用是一样的*/
}
</style>
<!-- The JavaScript -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('#col img').hover(
function(){
var $this = $(this);
$this.stop().animate({'opacity':'1.0','height':'200px','top':'0px','left':'0px'});
},
function(){
var $this = $(this);
$this.stop().animate({'opacity':'0.5','height':'500px','top':'-66.5px','left':'-150px'});
}
);
});
</script>
<body>
<div id="col">
<div class="pic">
<a href="#">
<img src="Images/1.jpg"/>
</a>
</div>
<div class="pic">
<a href="#">
<img src="Images/2.jpg"/>
</a>
</div>
<div class="pic">
<a href="#">
<img src="Images/3.jpg"/>
</a>
</div>
<div class="pic">
<a href="#">
<img src="Images/4.jpg"/>
</a>
</div>
<div class="pic">
<a href="#">
<img src="Images/5.jpg"/>
</a>
</div>
<div class="pic">
<a href="#">
<img src="Images/6.jpg"/>
</a>
</div>
</div>
</body>
</html>