jQuery實現鼠標懸浮在div上時候動態浮動另外一個div層蓋住第一個div層


<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.鼠標離開後效果

鼠標離開後效果圖



 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章