发新话题
打印

带缓冲的伸缩div隐藏层脚本

带缓冲的伸缩div隐藏层脚本

<!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>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script language="javascript">
var flag=0;
function f_s(id){
       var obj=document.getElementById(id);
       obj.style.display="block";
       obj.style.height="1px";  
       var changeW=function(){     
              var obj_h=parseInt(obj.style.height);
              if(obj_h<=350){
                     obj.style.height=(obj_h+Math.ceil((350-obj_h)/10))+"px";
              }
              else{
              clearInterval(bw1);
              }
       }      
       bw1= setInterval(changeW,1);
    if(flag>0){
      clearInterval(bw2);
    }
}
function closeW(id){
  flag++;
       var obj=document.getElementById(id);
       var closeDiv=function(){
      
        clearInterval(bw1);
              var obj_h=parseInt(obj.style.height);
              if(obj_h>1){
                     obj.style.height=(obj_h-Math.ceil(obj_h)/10)+"px";
              }
              else{
              clearInterval(bw2);
              obj.style.display="none";
              }
       }        
      bw2= setInterval(closeDiv,1);
//alert(flag)
}
function showDiv(){
 var ele = document.getElementById("div1");
 clearInterval(bw1);
 clearInterval(bw2);
 ele.style.display = "block";
 ele.style.height = 350 + "px";
}
</script>
</head>
<body>
<div onmouseover="f_s('div1')" onmouseout="closeW('div1')" style="position:absolute;background:black;left:50px;top:30px;width:150px;height:20px;color:#FFFFFF;">
鼠标放到这里看一看?</div>
<div id="div1" style="position:absolute;background:aqua;left:50px;overflow:hidden;top:50px;width:350px;display:none;" onmouseover="showDiv()" onmouseout="closeW('div1')">这个效果还不错吧?</div>
</body>
</html>

TOP

<html>
<head>
<title>div动画显示</title>
<style>
* { margin:0; padding:0;}
body { text-align:center; font:75% Verdana, Arial, Helvetica, sans-serif;}
h1 { font:125% Arial, Helvetica, sans-serif; text-align:left; font-weight:bolder; background:#333; padding:3px; display:block; color:#99CC00}
.class1 { width:40%; background:#CCC; position:relative; margin:0 auto; padding:5px;}
span { position:absolute; right:10px; top:8px; cursor:pointer; color:yellow;}
p { text-align:left; line-height:20px; background:#333; padding:3px; margin-top:5px; color:#99CC00}
#class1content { height:300px;overflow:hidden}
</style>
<script>
function $(element){
return element = document.getElementById(element);
}
function $D(){
var d=$('class1content');
var h=d.offsetHeight;
var maxh=300;
function dmove(){
h+=100; //设置层展开的速度
if(h>=maxh){
d.style.height='300px';
clearInterval(iIntervalId);
}else{
d.style.display='block';
d.style.height=h+'px';
}
}
iIntervalId=setInterval(dmove,2);
}
function $D2(){
var d=$('class1content');
var h=d.offsetHeight;
var maxh=300;
function dmove(){
h-=50;//设置层收缩的速度
if(h<=0){
d.style.display='none';
clearInterval(iIntervalId);
}else{
d.style.height=h+'px';
}
}
iIntervalId=setInterval(dmove,2);
}
function $use(){
var d=$('class1content');
var sb=$('stateBut');
if(d.style.display=='none'){
$D();
sb.innerHTML='×';
}else{
$D2();
sb.innerHTML='√';
}
}
</script>
</head>
<body>
<div class="class1">
<h1>Alone展开隐藏效果</h1>
<span id="stateBut" onclick="$use()">×</span>
<p id="class1content">小蜗牛问妈妈:为什么我们从生下来,就要背负这个又硬又重的壳呢?<br />
妈妈:因为我们的身体没有骨骼的支撑,只能爬,又爬不快。所以要这个壳的保护!<br />
小蜗牛:毛虫姊姊没有骨头,也爬不快,为什么她却不用背这个又硬又重的壳呢? <br />
妈妈:因为毛虫姊姊能变成蝴蝶,天空会保护她啊。 <br />
小蜗牛:可是蚯蚓弟弟也没骨头爬不快,也不会变成蝴蝶他什么不背这个又硬又重的壳呢? <br />
妈妈:因为蚯蚓弟弟会钻土, 大地会保护他啊。 <br />
小蜗牛哭了起来:我们好可怜,天空不保护,大地也不保护。 <br />
蜗牛妈妈安慰他:所以我们有壳啊!我们不靠天,也不靠地,我们靠自己。</p>
</div>
</body>
</html>

TOP

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>DOM_text01</title>
<style type="text/css">
body,span,div,td{font-size:12px;line-height:1.5em;color:#849BCA;}
#bodyL{
float:left;
width:84px;
margin-right:2px;
}
a.od{
width:80px;
height:25px;
line-height:25px;
text-align:center;
font-weight:bold;
border: 2px solid #849BCA;
display:block;
color:#547BC9;
float:left;
text-decoration:none;
margin-top:2px;
}
a.od:link{
background:#EEF1F8;
}
a.od:visited{
background:#EEF1F8;
}
a.od:hover{
background:#EEE;
}
a.od:active{
background:#EEE;
}
#fd{
width:500px;
height:200px;
background:#EDF1F8;
border: 2px solid #849BCA;
margin-top:2px;
margin-left:2px;
float:left;
overflow:hidden;
position:absolute;
left:0px;
top:0px;
cursor:move;
float:left;
/*filter:alpha(opacity=50);*/

}
.content{
padding:10px;
}
</style>
</head>
<body>
<div id="bodyL">
<a href="#" onclick = "show('fd');return false;">
[打开层]
</a>
<a href="#" onclick = "closeed('fd');return false;">
[关闭层]
</a>
</div>
<div id="fd" style="display:none;filter:alpha(opacity=100);opacity:1;">
<div class="content">移动层</div>
</div>

<script type="text/javascript">
var prox;
var proy;
var proxc;
var proyc;
function show(id){/*--打开--*/
clearInterval(prox);
clearInterval(proy);
clearInterval(proxc);
clearInterval(proyc);
var o = document.getElementById(id);
o.style.display = "block";
o.style.width = "1px";
o.style.height = "1px";
prox = setInterval(function(){openx(o,500)},10);
}
function openx(o,x){/*--打开x--*/
var cx = parseInt(o.style.width);
if(cx < x)
{
   o.style.width = (cx + Math.ceil((x-cx)/5)) +"px";
}
else
{
   clearInterval(prox);
   proy = setInterval(function(){openy(o,200)},10);
}
}
function openy(o,y){/*--打开y--*/
var cy = parseInt(o.style.height);
if(cy < y)
{
   o.style.height = (cy + Math.ceil((y-cy)/5)) +"px";
}
else
{
   clearInterval(proy);   
}
}
function closeed(id){/*--关闭--*/
clearInterval(prox);
clearInterval(proy);
clearInterval(proxc);
clearInterval(proyc);
var o = document.getElementById(id);
if(o.style.display == "block")
{
   proyc = setInterval(function(){closey(o)},10);   
}
}
function closey(o){/*--打开y--*/
var cy = parseInt(o.style.height);
if(cy > 0)
{
   o.style.height = (cy - Math.ceil(cy/5)) +"px";
}
else
{
   clearInterval(proyc);   
   proxc = setInterval(function(){closex(o)},10);
}
}
function closex(o){/*--打开x--*/
var cx = parseInt(o.style.width);
if(cx > 0)
{
   o.style.width = (cx - Math.ceil(cx/5)) +"px";
}
else
{
   clearInterval(proxc);
   o.style.display = "none";
}
}


/*-------------------------鼠标拖动---------------------*/
var od = document.getElementById("fd");
var dx,dy,mx,my,mouseD;
var odrag;
var isIE = document.all ? true : false;
document.onmousedown = function(e){
var e = e ? e : event;
if(e.button == (document.all ? 1 : 0))
{
   mouseD = true;   
}
}
document.onmouseup = function(){
mouseD = false;
odrag = "";
if(isIE)
{
   od.releaseCapture();
   od.filters.alpha.opacity = 100;
}
else
{
   window.releaseEvents(od.MOUSEMOVE);
   od.style.opacity = 1;
}
}


//function readyMove(e){
od.onmousedown = function(e){
odrag = this;
var e = e ? e : event;
if(e.button == (document.all ? 1 : 0))
{
   mx = e.clientX;
   my = e.clientY;
   od.style.left = od.offsetLeft + "px";
   od.style.top = od.offsetTop + "px";
   if(isIE)
   {
    od.setCapture();   
    od.filters.alpha.opacity = 50;
   }
   else
   {
    window.captureEvents(Event.MOUSEMOVE);
    od.style.opacity = 0.5;
   }
   
   //alert(mx);
   //alert(my);
   
}
}
document.onmousemove = function(e){
var e = e ? e : event;

//alert(mrx);
//alert(e.button);
if(mouseD==true && odrag)
{
   var mrx = e.clientX - mx;
   var mry = e.clientY - my;
   od.style.left = parseInt(od.style.left) +mrx + "px";
   od.style.top = parseInt(od.style.top) + mry + "px";   
   mx = e.clientX;
   my = e.clientY;
   
}
}


</script>
</body>
</html>

TOP

发新话题