| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 415 人关注过本帖
标题:求大大,达人们帮帮我吧!~
只看楼主 加入收藏
gtf7801524
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-3-29
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
求大大,达人们帮帮我吧!~
<script type="text/javascript">
var mh = 30;//高度
var step = 5;//每次变化的量
var ms = 10;//循环时间
function toggle(o){
  if (!o.tid)o.tid = "_" + Math.random() * 100;
  if (!window.toggler)window.toggler = {};
  if (!window.toggler[o.tid]){
    window.toggler[o.tid]={
      obj:o,
      maxHeight:o.offsetHeight,
      minHeight:mh,
      timer:null,
      action:1
    };
  }
  o.style.height = o.offsetHeight + "px";
  if (window.toggler[o.tid].timer)clearTimeout(window.toggler[o.tid].timer);
  window.toggler[o.tid].action *= -1;
  window.toggler[o.tid].timer = setTimeout("anim('"+o.tid+"')",ms );
}
function anim(id){
  var t = window.toggler[id];
  var o = window.toggler[id].obj;
  if (t.action < 0){
    if (o.offsetHeight <= t.minHeight){
      clearTimeout(t.timer);
      return;
    }
  }
  else{
    if (o.offsetHeight >= t.maxHeight){
      clearTimeout(t.timer);
      return;
    }
  }
  o.style.height = (parseInt(o.style.height, 10) + t.action * step) + "px";
  window.toggler[id].timer = setTimeout("anim('"+id+"')",ms );
}
</script>
<style type="text/css">
div.xx{border:solid 0px;overflow:hidden;}
div.xx h5{border:solid 0px;border-width:0 0 0px;padding:0;margin:0;height:28px;line-height:30px;cursor:pointer;background:#eee;}
</style>
</head>
<body>
<div class="xx"><h5 onclick="toggle(this.parentNode)">点击此处层伸缩</h5>
<p>test</p>
</div>
</body>

文字点击展开效果,可如让文字默认是收缩着的呢?求达人教教我吧~谢谢...
搜索更多相关主题的帖子: 时间 null function 
2011-03-29 17:24
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
收藏
得分:20 
给它设置css为display:none
2011-03-31 15:00
argont
Rank: 2
等 级:论坛游民
帖 子:13
专家分:10
注 册:2011-3-8
收藏
得分:0 
首先为你的<div class="xx">这里改为 <div id="menu" class="xx">

然后再将<body>改为  <body onload="toggle(document.getElementById('menu'));">

解决问题!!!!

http:///langzs/  web前端开发
2011-04-10 11:26
快速回复:求大大,达人们帮帮我吧!~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011850 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved