js實現div層緩慢收縮與展開的方法,jsdiv層展開

來源:互聯網
上載者:User

js實現div層緩慢收縮與展開的方法,jsdiv層展開

本文執行個體講述了js實現div層緩慢收縮與展開的方法。分享給大家供大家參考。具體分析如下:

這是一個層伸縮與展開的特效代碼,帶有點動畫效果,緩慢展開,DIV+JS聯合打造,看上去還不錯。不受內容約束,收縮與展開的速度是可以控制的,高度、迴圈時間也可以改。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>層收縮</title><script type="text/javascript">var mh = 30;//高度var step = 1;//每次變化的量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 1px;overflow:hidden;}div.xx h5{ border:solid 1px;border-width:0 0 1px; 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>Tomat6.0的配置視頻教程,AVI電影格式,相當清淅了,比起圖文版的教程更貼切,不會配置Tomcat的網友,你可不要錯過哦,由於視頻抓圖挺麻煩的,試了多次還是抓了一個不太清淅的,大家將就吧。</p></div></body></html>

希望本文所述對大家的javascript程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.