请帮着看看这段JS动画展开收缩脚本,急在线等 本帖最后由 nickwang888 于 2009-09-13 23:44:06 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!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>JS动画展开收缩显示层 </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} #class1content1 { height:300px;overflow:hidden} #class1content2 { height:300px;overflow:hidden} </style> <script type="text/javascript"> function $(element){ return element = document.getElementById(element); } function $D1(obj){ var h=obj.offsetHeight; var maxh=300; function dmove(){ h+=20; //设置层展开的速度 if(h>=maxh){ obj.style.height=maxh+'px'; clearInterval(iIntervalId); }else{ obj.style.display='block'; obj.style.height=h+'px'; } } iIntervalId=setInterval(dmove,2); } function $D2(obj){ var h=obj.offsetHeight; var maxh=300; function dmove(){ h-=20;//设置层收缩的速度 if(h <=0){ obj.style.display='none'; clearInterval(iIntervalId); }else{ obj.style.display='block'; obj.style.height=h+'px'; } } iIntervalId=setInterval(dmove,2); } function $use(obj){ var obj=$(obj); var sb=event.srcElement.parentNode; //$('stateBut'); if(obj.style.display=='none'){ $D1(obj); sb.innerHTML=' <img name="" src="" width="16" height="16" alt="收起" style="background-color: #000000" />'; }else{ $D2(obj); sb.innerHTML=' <img name="" src="" width="16" height="16" alt="展开" style="background-color: #FF0000" />'; } } </script> </head> <body> <div class="class1"> <h1>展开收缩动画层效果 </h1> <span id="stateBut" onclick="$use('class1content1')"> <img name="" src="" width="16" height="16" alt="收起" style="background-color: #000000" /> </span> <p id="class1content1">小蜗牛问妈妈:为什么我们从生下来,就要背负这个又硬又重的壳呢? <br /> 妈妈:因为我们的身体没有骨骼的支撑,只能爬,又爬不快。所以要这个壳的保护! <br /> 小蜗牛:毛虫姊姊没有骨头,也爬不快,为什么她却不用背这个又硬又重的壳呢? <br /> 妈妈:因为毛虫姊姊能变成蝴蝶,天空会保护她啊。 <br /> 小蜗牛:可是蚯蚓弟弟也没骨头爬不快,也不会变成蝴蝶他什么不背这个又硬又重的壳呢? <br /> 妈妈:因为蚯蚓弟弟会钻土, 大地会保护他啊。 <br /> 小蜗牛哭了起来:我们好可怜,天空不保护,大地也不保护。 <br /> 蜗牛妈妈安慰他:所以我们有壳啊!我们不靠天,也不靠地,我们靠自己。 </p> </div> <div class="class1"> <h1>展开收缩动画层效果 </h1> <span id="stateBut" onclick="$use('class1content2')"> <img name="" src="" width="16" height="16" alt="收起" style="background-color: #000000" /> </span> <p id="class1content2">小蜗牛问妈妈:为什么我们从生下来,就要背负这个又硬又重的壳呢? <br /> 妈妈:因为我们的身体没有骨骼的支撑,只能爬,又爬不快。所以要这个壳的保护! <br /> 小蜗牛:毛虫姊姊没有骨头,也爬不快,为什么她却不用背这个又硬又重的壳呢? <br /> 妈妈:因为毛虫姊姊能变成蝴蝶,天空会保护她啊。 <br /> 小蜗牛:可是蚯蚓弟弟也没骨头爬不快,也不会变成蝴蝶他什么不背这个又硬又重的壳呢? <br /> 妈妈:因为蚯蚓弟弟会钻土, 大地会保护他啊。 <br /> 小蜗牛哭了起来:我们好可怜,天空不保护,大地也不保护。 <br /> 蜗牛妈妈安慰他:所以我们有壳啊!我们不靠天,也不靠地,我们靠自己。 </p> </div> </body> </html> 感谢 hookee问题解决啦 easyui-combobox 请教jQuery操作ListBox的问题 请教一下构造函数原型的问题 急!!!!!!!!!!!! 子窗口未关,不能操作父窗口,怎么实现?在线等 如何防止页面刷新? 各位兄弟看看小弟做的OA吧!!!多提意见,多交流 阿沐进来看看3 打印!!!打印 jquery input选择框,通过身份证获取性别显示问题 如何获得input两个值 为什么我这个提交前的判断不起作用?
<!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>JS动画展开收缩显示层 </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}
#class1content1 { height:300px;overflow:hidden}
#class1content2 { height:300px;overflow:hidden}
</style>
<script type="text/javascript">
function $(element){
return element = document.getElementById(element);
} function $D1(obj){
var h=obj.offsetHeight;
var maxh=300;
function dmove(){
h+=20; //设置层展开的速度
if(h>=maxh){
obj.style.height=maxh+'px';
clearInterval(iIntervalId);
}else{
obj.style.display='block';
obj.style.height=h+'px';
}
}
iIntervalId=setInterval(dmove,2);
} function $D2(obj){
var h=obj.offsetHeight;
var maxh=300;
function dmove(){
h-=20;//设置层收缩的速度
if(h <=0){
obj.style.display='none';
clearInterval(iIntervalId);
}else{
obj.style.display='block';
obj.style.height=h+'px';
}
}
iIntervalId=setInterval(dmove,2);
} function $use(obj){
var obj=$(obj);
var sb=event.srcElement.parentNode; //$('stateBut');
if(obj.style.display=='none'){
$D1(obj);
sb.innerHTML=' <img name="" src="" width="16" height="16" alt="收起" style="background-color: #000000" />';
}else{
$D2(obj);
sb.innerHTML=' <img name="" src="" width="16" height="16" alt="展开" style="background-color: #FF0000" />';
}
}
</script>
</head>
<body>
<div class="class1">
<h1>展开收缩动画层效果 </h1>
<span id="stateBut" onclick="$use('class1content1')"> <img name="" src="" width="16" height="16" alt="收起" style="background-color: #000000" /> </span>
<p id="class1content1">小蜗牛问妈妈:为什么我们从生下来,就要背负这个又硬又重的壳呢? <br />
妈妈:因为我们的身体没有骨骼的支撑,只能爬,又爬不快。所以要这个壳的保护! <br />
小蜗牛:毛虫姊姊没有骨头,也爬不快,为什么她却不用背这个又硬又重的壳呢? <br />
妈妈:因为毛虫姊姊能变成蝴蝶,天空会保护她啊。 <br />
小蜗牛:可是蚯蚓弟弟也没骨头爬不快,也不会变成蝴蝶他什么不背这个又硬又重的壳呢? <br />
妈妈:因为蚯蚓弟弟会钻土, 大地会保护他啊。 <br />
小蜗牛哭了起来:我们好可怜,天空不保护,大地也不保护。 <br />
蜗牛妈妈安慰他:所以我们有壳啊!我们不靠天,也不靠地,我们靠自己。 </p>
</div>
<div class="class1">
<h1>展开收缩动画层效果 </h1>
<span id="stateBut" onclick="$use('class1content2')"> <img name="" src="" width="16" height="16" alt="收起" style="background-color: #000000" /> </span>
<p id="class1content2">小蜗牛问妈妈:为什么我们从生下来,就要背负这个又硬又重的壳呢? <br />
妈妈:因为我们的身体没有骨骼的支撑,只能爬,又爬不快。所以要这个壳的保护! <br />
小蜗牛:毛虫姊姊没有骨头,也爬不快,为什么她却不用背这个又硬又重的壳呢? <br />
妈妈:因为毛虫姊姊能变成蝴蝶,天空会保护她啊。 <br />
小蜗牛:可是蚯蚓弟弟也没骨头爬不快,也不会变成蝴蝶他什么不背这个又硬又重的壳呢? <br />
妈妈:因为蚯蚓弟弟会钻土, 大地会保护他啊。 <br />
小蜗牛哭了起来:我们好可怜,天空不保护,大地也不保护。 <br />
蜗牛妈妈安慰他:所以我们有壳啊!我们不靠天,也不靠地,我们靠自己。 </p>
</div>
</body>
</html>
问题解决啦