以前曾寫過(guò)一個(gè),不過(guò)太麻煩了,呵呵```
現(xiàn)在改進(jìn)了一下,
其實(shí)很簡(jiǎn)單:css定位層一直在右下角,用js控制層的高度增減。
代碼:
<!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>測(cè)試</title>
<style type="text/css">
.divCss{
bottom:0;
display:block;
height:25px;
overflow:hidden;
padding:0;
position:fixed;
right:20px;
}
.contentCss{
background:#666;
height:200px;
width:200px;
}
.contentCssHeight{
}
.titleCss{
width:200px;
height:25px;
line-height:25px;
text-align:right;
margin:0px;
background:#999999;
}
#close{
cursor:pointer;
}
</style>
<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function(){
//標(biāo)題層的高度--提示打開或關(guān)閉
var titHeight=$("#ditTitle").height();
//內(nèi)容層的高度
var conHeight=$("#divContent").height();
//打開或關(guān)閉
$("#close").toggle(function(){
//改變提示
$("#close").text("關(guān)閉");
//動(dòng)畫--一秒內(nèi)消息層高度增加,top增加
$("#msgDiv").animate({height:titHeight+conHeight},1000,function(){
//展開后執(zhí)行的函數(shù)
});
},function(){
//改變提示
$("#close").text("打開");
//alert(temp+" "+titHeight);
$("#msgDiv").animate({height:titHeight},1000,function(){
//關(guān)閉后執(zhí)行的函數(shù)
});
})
//執(zhí)行
var myTimer,i=8;
function starFun()
{
//觸發(fā)click事件,顯示
if(i==4)
{
$("#close").click();
}
//清除timeout,觸發(fā)click事件,關(guān)閉層
if(i==0)
{
window.clearTimeout(myTimer);
if($("#close").text()!="打開")
$("#close").click();
}
myTimer=window.setTimeout(starFun,1000);
i=i-1;
}
starFun()
});
</script>
</head>
<body>
<div style="height: 1000px; background: #ccc;">
測(cè)試Div</div>
<div id="msgDiv" class="divCss">
<div id="ditTitle" class="contentCssHeight titleCss">
<span id="close">打開</span></div>
<div id="divContent" class="contentCss">
這是一些測(cè)試內(nèi)容</div>
</div>
<div style="height: 1000px; background: #C0C0C0;">
測(cè)試Div</div>
</body>
</html>
聯(lián)系客服