<head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<script src="js/jquery-1.5.1.js" type="text/javascript"></script>
<style type="text/css">
.caption{
width:200px;
height:100px;
background-color:red;
position:fixed;
}
.layer{
width:200px;
background-color:blue;
position:fixed;
margin-top:100px;/*和div的高度一致*/
display:none;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$(".caption").hover(function(){
$(".layer",this).stop().animate({height:'100px',marginTop:'0px',opacity:'toggle'});
},function(){
$(".layer",this).stop().animate({height:'0px',marginTop:'100px',opacity:'toggle'});
});
})
</script>
</head>
<body>
<div class="caption">
<div class="layer"></div>
</div>
</body>
</html>
效果圖:懸浮層是使用jquery中的動畫淡入淡出的!
1.初始狀態
2.鼠標懸浮效果
3.鼠標離開後效果