87,907
社区成员
发帖
与我相关
我的任务
分享
<!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></title>
<style type="text/css">
#divList{position:relative;}
.divClass{ width:300px; height:100px; background:orange; float:left; margin:0 10px; position:absolute}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
//使用position定位div,避免发生布局变化
$("#divList div.divClass").each(function(){
var i = $(this).index();
$(this).css({"left":i*310});
})
//div隐藏显示
$("#divList div.divClass").hover(function(){
$(this).siblings().fadeOut(); //鼠标经过
},function(){
$("#divList div.divClass").fadeIn(); //鼠标离开
})
})
</script>
</head>
<body>
<div id="divList">
<div class="divClass">1 </div>
<div class="divClass">2 </div>
<div class="divClass">3 </div>
<div class="divClass">4 </div>
</div>
</body>
</html>