国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JS簡單實現動畫彈出層效果

2024-05-06 16:19:21
字體:
來源:轉載
供稿:網友

本文給大家介紹的是是一款javascript彈出層特效,支持點擊觸發js彈出層,滑過觸發js彈出層,帶動畫效果js彈出層,可自定義函數回調js彈出層。

JS簡單實現動畫彈出層效果

 

 
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. <head> 
  4. <title>動畫彈出層</title> 
  5. <style> 
  6. .list{ 
  7. position:relative;; 
  8. background:#eee; 
  9. border:1px #ccc solid; 
  10. margin:10px; 
  11. height:30px; 
  12. width:100px; 
  13. cursor :pointer ; 
  14. .listShow{ 
  15. position:relative; 
  16. background:#eff; 
  17. border:1px #ddd solid; 
  18. margin:10px; 
  19. height:30px; 
  20. width:100px; 
  21. cursor :pointer ; 
  22. .comment{ 
  23. position:absolute; 
  24. left:0; 
  25. display:none; 
  26. position:absolute; 
  27. border:1px #ccc solid; 
  28. background:#fee; 
  29. width:200px; 
  30. height:200px; 
  31. overflow:hidden; 
  32. z-index:100; 
  33. </style> 
  34. </head> 
  35. <body> 
  36. <div class="" id="show"
  37. </div> 
  38. <div class="list" id="list1">1 
  39. <div class="comment" id="comment1">內容顯示111<br/> 
  40. </div> 
  41. <div class="list" id="list2">2 
  42. <div class="comment" id="comment2">內容顯示222</div> 
  43. </div> 
  44. <div class="list" id="list3">3 
  45. <div class="comment" id="comment3">內容顯示333</div> 
  46. </div> 
  47. </body> 
  48. </html> 
  49. <script> 
  50. var zindex=0; 
  51. function $id(id){ 
  52. return document.getElementById(id); 
  53. var Bind = function(object,fun){ 
  54. var args = Array.prototype.slice.call(arguments).slice(2); 
  55. return function(){ 
  56. return fun.apply(object,args); 
  57. function addEventHandler(oTarget, sEventType, fnHandler){  
  58. if(oTarget.addEventListener){oTarget.addEventListener(sEventType, fnHandler, false);} 
  59. else if(oTarget.attachEvent){oTarget.attachEvent('on' + sEventType, fnHandler);} 
  60. else{oTarget['on' + sEventType] = fnHandler;} 
  61. var Shower=function(){ 
  62. this.list=null
  63. this.comment=null
  64. this.moveLeft=80;  
  65. this.moveTop=20; 
  66. this.height=150; 
  67. this.width=250; 
  68. this.time=800; 
  69. this.init=function(lisObj,comObj){ 
  70. this.list=lisObj; 
  71. this.comment=comObj; 
  72. var _this=this
  73. this._fnMove=Bind(this,this.move); 
  74. (function(){ 
  75. var obj=_this; 
  76. addEventHandler(obj.list,"click",obj._fnMove); 
  77. })(); 
  78. }; 
  79. this.move=function(){ 
  80. var _this=this
  81. var w=0;  
  82. var h=0;  
  83. var height=0; //彈出div的高 
  84. var width=0; //彈出div的寬 
  85. var t=0; 
  86. var startTime = new Date().getTime();//開始執行的時間 
  87. if(!_this.comment.style.display||_this.comment.style.display=="none"){ 
  88. _this.comment.style.display="block"
  89. _this.comment.style.height=0+"px"
  90. _this.comment.style.width=0+"px"
  91. _this.list.style.zIndex=++zindex; 
  92. _this.list.className="listShow"
  93. var comment=_this.comment.innerHTML;  
  94. _this.comment.innerHTML=""//去掉顯示內容 
  95. var timer=setInterval(function(){ 
  96. var newTime = new Date().getTime(); 
  97. var timestamp = newTime - startTime; 
  98. _this.comment.style.left=Math.ceil(w)+"px"
  99. _this.comment.style.top=Math.ceil(h)+"px"
  100. _this.comment.style.height=height+"px"
  101. _this.comment.style.width=width+"px"
  102. t++; 
  103. var change=(Math.pow((timestamp/_this.time-1), 3) +1); //根據運行時間得到基礎變化量 
  104. w=_this.moveLeft*change; 
  105. h=_this.moveTop*change; 
  106. height=_this.height*change; 
  107. width=_this.width*change; 
  108. $id("show").innerHTML=w; 
  109. if(w>_this.moveLeft){ 
  110. clearInterval(timer); 
  111. _this.comment.style.left=_this.moveLeft+"px"
  112.  
  113. _this.comment.style.top=_this.moveTop+"px"; _this.comment.style.height=_this.height+"px"
  114.  
  115. _this.comment.style.width=_this.width+"px"
  116. _this.comment.innerHTML=comment; //回復顯示內容 
  117. },1,_this.comment); 
  118. }else
  119. _this.hidden(); 
  120. this.hidden=function(){ 
  121. var _this=this
  122. var flag=1; 
  123. var hiddenTimer=setInterval(function(){ 
  124. if(flag==1){ 
  125. _this.comment.style.height=parseInt(_this.comment.style.height)-10+"px"
  126. }else{ _this.comment.style.width=parseInt(_this.comment.style.width)-15+"px"
  127. _this.comment.style.left=parseInt(_this.comment.style.left)+5+"px"
  128. if(flag==1 && parseInt(_this.comment.style.height)<10){ 
  129. flag=-flag; 
  130. if(parseInt(_this.comment.style.width)<20){ 
  131. clearInterval(hiddenTimer); 
  132. _this.comment.style.left="0px"
  133. _this.comment.style.top="0px"
  134. _this.comment.style.height="0px"
  135. _this.comment.style.width="0px"
  136. _this.comment.style.display="none"
  137. if(_this.list.style.zIndex==zindex){ 
  138. zindex--; 
  139. }; 
  140. _this.list.style.zIndex=0; 
  141. _this.list.className="list"
  142. },1) 
  143. window.onload=function(){ 
  144. //建立各個菜單對象 
  145. var shower1=new Shower(); 
  146. shower1.init($id("list1"),$id("comment1")); 
  147. var shower2=new Shower(); 
  148. shower2.init($id("list2"),$id("comment2")); 
  149. var shower3=new Shower(); 
  150. shower3.init($id("list3"),$id("comment3")); 
  151. </script> 

以上所述就是本文的全部內容了,希望大家能夠喜歡。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 兴和县| 文化| 应城市| 交城县| 乌拉特中旗| 牙克石市| 华容县| 永顺县| 汪清县| 吴桥县| 商丘市| 金阳县| 云林县| 通河县| 南平市| 新宁县| 鸡东县| 林西县| 凭祥市| 南宫市| 丹江口市| 洛宁县| 白河县| 吉安县| 揭西县| 勃利县| 南汇区| 抚宁县| 普兰店市| 长治县| 中牟县| 吉首市| 淄博市| 和平县| 克山县| 南乐县| 赫章县| 文成县| 普格县| 连州市| 黄梅县|