层展开/关闭 运动缓冲效果

来源:互联网 发布:腹黑兔子无耻外交 知乎 编辑:程序博客网 时间:2024/04/27 16:44
<script type="text/javascript"><!--google_ad_client = "pub-4490194096475053";/* 内容页,300x250,第一屏 */google_ad_slot = "3685991503";google_ad_width = 300;google_ad_height = 250;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

http://www.corange.cn/archives/2008/10/1930.html

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN"> 
  3. <head> 
  4. <title>层展开/关闭 - 运动缓冲效果</title> 
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
  6. <script type="text/javascript"> 
  7. /* 
  8. 函数名称: Scroll 
  9. Scroll(obj, h, s) 
  10. 参数说明: 
  11. obj,[object] id值或对象. 必需 
  12. h,[height] 展开后的高度. 可选(默认为200px) 
  13. s,[speed] 展开速度,值越小展开速度越慢. 可选(默认为1.2){建议取值为1.1到2.0之间[例如:1.17]}. 
  14. 函数返回值: 
  15. true 展开(对象的高度等于展开后的高度) 
  16. false 关闭(对象的高度等于原始高度) 
  17. */ 
  18. function Scroll(obj, h, s){ 
  19. if(obj == undefined){return false;} 
  20. var hh = h || 200; 
  21. var ss = s || 1.2; 
  22. var obj = typeof(obj)=="string"?document.getElementById(obj):obj; 
  23. var status = obj.getAttribute("status")==null; 
  24. var oh = parseInt(obj.offsetHeight); 
  25. obj.style.height = oh
  26. obj.style.display = "block"
  27. obj.style.overflow = "hidden"
  28. if(obj.getAttribute("oldHeight") == null){ 
  29. obj.setAttribute("oldHeight", oh); 
  30. }else{ 
  31. var oldH = Math.ceil(obj.getAttribute("oldHeight")); 
  32. var reSet = function(){ 
  33. if(status){ 
  34. if(oh < h){ 
  35. oh = Math.ceil(h-(h-oh)/s); 
  36. obj.style.height = oh+"px"; 
  37. }else{ 
  38. obj.setAttribute("status",false); 
  39. window.clearInterval(IntervalId); 
  40. }else{ 
  41. obj.style.height = oldH+"px"; 
  42. obj.removeAttribute("status"); 
  43. window.clearInterval(IntervalId); 
  44. var IntervalId = window.setInterval(reSet,10); 
  45. return status; 
  46. window.onloadfunction(){ 
  47. document.getElementById('detail').onclick = function(){ 
  48. Scroll('detail', 300, 1.3); 
  49. document.getElementById('text').onclick = function(){ 
  50. Scroll('text'); 
  51. </script> 
  52. </head> 
  53. <body> 
  54. <p id="detail" style="border:1px dashed #f00;">这是一个段落啦!!哇哈哈哈<br/>点我一下下啦:)</p> 
  55. <div id="text" style="border:1px solid #0f0">Hello World!<br/>点击展开www.corange.cn</div> 
  56. <button onclick="Scroll('text', 400, 1.2)">Hello World</button> 
  57. </body> 
  58. </html> 
<script type="text/javascript"><!--google_ad_client = "pub-4490194096475053";/* 728x90, 创建于 08-12-8 */google_ad_slot = "0403648181";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击