.Net软件开发技术研究

Asp.Net软件开发

博客园 首页 新随笔 联系 订阅 管理
  5 Posts :: 0 Stories :: 6 Comments :: 0 Trackbacks

置顶随笔 #

摘要: 说明:本指南由网友自愿参与翻译,翻译不当之处还望大家指出阅读全文
posted @ 2008-06-15 14:28 Mars Mitchell 阅读(687) 评论(3) 编辑

2009年3月27日 #

【实例描述】

折叠的div是网页显示内容的重要手段,因为使用折叠效果可以节省页面的空间,同时也提高了页面的美观性。本例学习如何制作一个简单的div折叠效果。

【实现代码】

<script type="text/javascript">

var mh = 30; //最小高度

var step = 1; //每次变化的px量

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>

【运行效果】

div的折叠效果如图5-4所示,展开效果如图5-5所示。

               

图5-4  div折叠效果                              图5-5  div展开效果

【难点剖析】

本例的重点是对象的创建,如“toggler”就是自己创建的一个对象,其包含obj、maxHeight等属性,可以在脚本方法中调用这些属性,此实现类似于面向对象的设计方法。

posted @ 2009-03-27 12:33 Mars Mitchell 阅读(960) 评论(0) 编辑

2008年6月21日 #

摘要: 小偷开锁工具大曝光 传说中的万能钥匙阅读全文
posted @ 2008-06-21 13:08 Mars Mitchell 阅读(447) 评论(1) 编辑

2008年6月16日 #

摘要: 2007年6月清华大学出版社出版 69元(光盘1张)阅读全文
posted @ 2008-06-16 12:48 Mars Mitchell 阅读(483) 评论(2) 编辑

2008年6月15日 #

摘要: 说明:本指南由网友自愿参与翻译,翻译不当之处还望大家指出阅读全文
posted @ 2008-06-15 14:28 Mars Mitchell 阅读(687) 评论(3) 编辑

摘要: Security Tutorials系列文章阅读全文
posted @ 2008-06-15 00:40 Mars Mitchell 阅读(527) 评论(0) 编辑