層展開/關閉 - 運動緩衝效果二

來源:互聯網
上載者:User
提示:您可以先修改部分代碼再運行

<!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" xml:lang="zh-CN" lang="zh-CN"><head><title>層展開/關閉 - 運動緩衝效果</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta name="keywords" content="小秦,展開,關閉,運動緩衝,效果,javascript,封裝" /><meta name="description" content="展開/關閉 - 運動緩衝效果" /><meta name="copyright" content="Copyright 2008 XQin.cn" /><meta name="author" content="小秦" /><script type="text/javascript">/* 函數名稱: Scroll Scroll(obj, h, s) 參數說明: obj,[object] id值或對象. 必需 h,[height] 展開後的高度. 可選(預設為200px) s,[speed] 展開速度,值越小展開速度越慢. 可選(預設為1.2){建議取值為1.1到2.0之間[例如:1.17]}. 函數傳回值: true 展開(對象的高度等於展開後的高度) false 關閉(對象的高度等於原始高度)*/function Scroll(obj, h, s){ if(obj == undefined){return false;} var h = h || 200; var s = s || 1.2; var obj = typeof(obj)=="string"?document.getElementById(obj):obj; var status = obj.getAttribute("status")==null; var oh = parseInt(obj.offsetHeight); obj.style.height = oh; obj.style.display = "block";obj.style.overflow = "hidden"; if(obj.getAttribute("oldHeight") == null){ obj.setAttribute("oldHeight", oh); }else{ var oldH = Math.ceil(obj.getAttribute("oldHeight")); } var reSet = function(){ if(status){ if(oh < h){ oh = Math.ceil(h-(h-oh)/s); obj.style.height = oh+"px"; }else{ obj.setAttribute("status",false); window.clearInterval(IntervalId); } }else{ obj.style.height = oldH+"px"; obj.removeAttribute("status"); window.clearInterval(IntervalId); } } var IntervalId = window.setInterval(reSet,10);return status;}window.onload= function(){ document.getElementById('detail').onclick = function(){ Scroll('detail', 300, 1.3); } document.getElementById('text').onclick = function(){ Scroll('text'); }}</script></head><body><p id="detail" >這是一個段落啦!!哇哈哈哈<br/>點我一下下啦:)</p><div id="text" >Hello World!<br/>你敢點我不 -_|||</div><button onclick="Scroll('text', 400, 1.2)">Hello World</button></body></html>
提示:您可以先修改部分代碼再運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.