<script type="text/javascript" language="javascript">
function $(obj)
{
return document.getElementById(obj);
}
function ToggleDiv()
{
this.ToggleId='silder'; //被伸缩的对象ID
this.ParentId='container'; //被伸缩的对象的父ID
this.minHeight=1; //最小高度
this.maxHeight=200; //最大高度
this.speed=1; //伸缩速度
this.offset=0.15; //偏移量
this.load=function()
{
if($(this.ToggleId).style.display=='none') //如果是隐藏的就打开
{
StartToggle('open',this.ToggleId,this.ParentId,this.minHeight,this.maxHeight,this.speed,this.offset);
}
else //如果是打开的就隐藏
{
StartToggle('close',this.ToggleId,this.ParentId,this.minHeight,this.maxHeight,this.speed,this.offset);
}
}
}
function StartToggle(method,toggleid,parentid,minheight,maxheight,speed,offset)
{
if(typeof(method)!='string' || method.toLowerCase()=='')
{
method='open';
}
if(method.toLowerCase()=='open')
{
var addspeed=speed+offset;
var openfun=function()
{
var originheight=$(toggleid).offsetHeight==0?1:$(toggleid).offsetHeight;
var newheight=originheight+addspeed;
addspeed=addspeed+offset;
if(parseInt(newheight)<parseInt(maxheight))
{
$(toggleid).style.height=newheight+'px';
$(toggleid).style.display='block';
}
else if(parseInt(newheight)>=parseInt(maxheight))
{
$(toggleid).style.height=maxheight+'px';
$(toggleid).style.display='block';
$(parentid).innerHTML='收缩';
window.clearInterval(addtimer);
}
}
var addtimer=window.setInterval(openfun,100);
}
else if(method.toLowerCase()=='close')
{
var addspeed=speed+offset;
var reducefunction=function()
{
var originheight=$(toggleid).offsetHeight;
var newheight=originheight-addspeed;
addspeed=addspeed+offset;
if(parseInt(newheight)>parseInt(minheight))
{
$(toggleid).style.height=newheight+'px';
$(toggleid).style.display='block';
}
else
{
$(toggleid).style.display='none';
$(toggleid).style.height='1px';
$(parentid).innerHTML='展开';
window.clearInterval(reducetimer);
}
}
var reducetimer=window.setInterval(reducefunction,100);
}
}
function DoToggle(obj1,obj2)
{
var tog=new ToggleDiv();
tog.ToggleId=obj1;
tog.ParentId=obj2;
tog.minHeight=5;
tog.maxHeight=110;
tog.speed=10;
tog.offset=3;
tog.load();
}
</script>
<div style="border:1px dashed blue;width:200px;">
<h2 id="container" onclick="javascript:DoToggle('silder',this.id);" onmouseover="this.style.cursor='pointer';">展开</h2>
<div id="silder" style="display:none">
伸缩效果<br />
伸缩效果<br />
伸缩效果<br />
伸缩效果<br />伸缩效果<br />
伸缩效果<br />
</div>
</div>
function a()
{
setTimeout(function(){alert('1');},0);
alert('2');
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有