CSS+JavaScript控制层显示与隐藏,感觉还行吧,现在经常用到这种效果,兼容性不错。
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>层的展开折叠</title>
<body>
<style>
<!--
.drag{position:relative;cursor:hand
}
#scontentmain{
position:absolute;
width:150px;
}
#scontentbar{
cursor:hand;
position:absolute;
background-color:green;
height:15;
width:100%;
top:0;
font: 9pt;
}
#scontentsub{
position:absolute;
width:100%;
top:15;
background-color:lightyellow;
border:2px solid green;
padding:1.5px;
}
-->
</style>
<script language="JavaScript1.2">
<!--
var dragapproved=false
var zcor,xcor,ycor
function movescontentmain(){
if (event.button==1&&dragapproved){
zcor.style.pixelLeft=tempvar1+event.clientX-xcor
zcor.style.pixelTop=tempvar2+event.clientY-ycor
leftpos=document.all.scontentmain.style.pixelLeft-document.body.scrollLeft
toppos=document.all.scontentmain.style.pixelTop-document.body.scrollTop
return false
}
}
function dragscontentmain(){
if (!document.all)
return
if (event.srcElement.id=="scontentbar"){
dragapproved=true
zcor=scontentmain
tempvar1=zcor.style.pixelLeft
tempvar2=zcor.style.pixelTop
xcor=event.clientX
ycor=event.clientY
document.οnmοusemοve=movescontentmain
}
}
document.οnmοusedοwn=dragscontentmain
document.οnmοuseup=new Function("dragapproved=false")
//-->
</script>
<div id="scontentmain">
<div id="scontentbar" onClick="onoffdisplay()" align="right">
<b><font color="#FFFFFF">
<span size=1>显示/隐藏</span>
</font></b>
</div>
<div id="scontentsub">
<font face="Arial"><small><small>这里是一段测试文字 ,感觉还行吧,CSS配合JS完成的层的展开与折叠效果。</small></small></font></p>
</div>
</div>
<script language="JavaScript1.2">
var w=document.body.clientWidth-195
var h=50
w+=document.body.scrollLeft
h+=document.body.scrollTop
var leftpos=w
var toppos=h
scontentmain.style.left=w
scontentmain.style.top=h
function onoffdisplay(){
if (scontentsub.style.display=='')
scontentsub.style.display='none'
else
scontentsub.style.display=''
}
function staticize(){
w2=document.body.scrollLeft+leftpos
h2=document.body.scrollTop+toppos
scontentmain.style.left=w2
scontentmain.style.top=h2
}
window.οnscrοll=staticize
</script>
</body>
</html>