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

首頁 > 語言 > JavaScript > 正文

JavaScript實(shí)現(xiàn)圖片DIV豎向滑動(dòng)的方法

2024-05-06 16:18:47
字體:
供稿:網(wǎng)友

這篇文章主要介紹了JavaScript實(shí)現(xiàn)圖片DIV豎向滑動(dòng)的方法,涉及javascript操作div層的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了JavaScript實(shí)現(xiàn)圖片DIV豎向滑動(dòng)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  3. <html xmlns="http://www.w3.org/1999/xhtml"><head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  5. <title>圖片滑動(dòng)展示效果</title> 
  6. <script type="text/javascript"
  7. var $ = function (id) { 
  8. return "string" == typeof id ? document.getElementById(id) : id; 
  9. }; 
  10. function Event(e){ 
  11. var oEvent = document.all ? window.event : e; 
  12. if (document.all) { 
  13. if(oEvent.type == "mouseout") { 
  14. oEvent.relatedTarget = oEvent.toElement; 
  15. }else if(oEvent.type == "mouseover") { 
  16. oEvent.relatedTarget = oEvent.fromElement; 
  17. return oEvent; 
  18. function addEventHandler(oTarget, sEventType, fnHandler) { 
  19. if (oTarget.addEventListener) { 
  20. oTarget.addEventListener(sEventType, fnHandler, false); 
  21. else if (oTarget.attachEvent) { 
  22. oTarget.attachEvent("on" + sEventType, fnHandler); 
  23. else { 
  24. oTarget["on" + sEventType] = fnHandler; 
  25. }; 
  26. var Class = { 
  27. create: function() { 
  28. return function() { 
  29. this.initialize.apply(this, arguments); 
  30. Object.extend = function(destination, source) { 
  31. for (var property in source) { 
  32. destination[property] = source[property]; 
  33. return destination; 
  34.  
  35.  
  36. var GlideView = Class.create(); 
  37. GlideView.prototype = { 
  38. //容器對象 容器寬度 展示標(biāo)簽 展示寬度 
  39. initialize: function(obj, iHeight, sTag, iMaxHeight, options) { 
  40. var oContainer = $(obj), oThis=this, len = 0; 
  41. this.SetOptions(options); 
  42. this.Step = Math.abs(this.options.Step); 
  43. this.Time = Math.abs(this.options.Time); 
  44. this._list = oContainer.getElementsByTagName(sTag); 
  45. len = this._list.length; 
  46. this._count = len; 
  47. this._height = parseInt(iHeight / len); 
  48. this._height_max = parseInt(iMaxHeight); 
  49. this._height_min = parseInt((iHeight - this._height_max) / (len - 1)); 
  50. this._timer = null
  51. this.Each(function(oList, oText, i){ 
  52. oList._target = this._height * i;//自定義一個(gè)屬性放目標(biāo)left 
  53. oList.style.top = oList._target + "px"
  54. oList.style.position = "absolute"
  55. addEventHandler(oList, "mouseover"function(){ oThis.Set.call(oThis, i); }); 
  56. }) 
  57. //容器樣式設(shè)置 
  58. oContainer.style.height = iHeight + "px"
  59. oContainer.style.overflow = "hidden"
  60. oContainer.style.position = "relative"
  61. //移出容器時(shí)返回默認(rèn)狀態(tài) 
  62. addEventHandler(oContainer, "mouseout"function(e){ 
  63. //變通防止執(zhí)行oList的mouseout 
  64. var o = Event(e).relatedTarget; 
  65. if (oContainer.contains ? !oContainer.contains(o) : oContainer != o && !(oContainer.compareDocumentPosition(o) & 16)) oThis.Set.call(oThis, -1); 
  66. }) 
  67. }, 
  68. //設(shè)置默認(rèn)屬性 
  69. SetOptions: function(options) { 
  70. this.options = {//默認(rèn)值 
  71. Step:20,//滑動(dòng)變化率 
  72. Time:3,//滑動(dòng)延時(shí) 
  73. TextTag:"",//說明容器tag 
  74. TextHeight: 0//說明容器高度 
  75. }; 
  76. Object.extend(this.options, options || {}); 
  77. }, 
  78. //相關(guān)設(shè)置 
  79. Set: function(index) { 
  80. if (index < 0) { 
  81. //鼠標(biāo)移出容器返回默認(rèn)狀態(tài) 
  82. this.Each(function(oList, oText, i){ oList._target = this._height * i; if(oText){ oText._target = this._height_text; } }) 
  83. else { 
  84. //鼠標(biāo)移到某個(gè)滑動(dòng)對象上 
  85. this.Each(function(oList, oText, i){ 
  86. oList._target = (i <= index) ? this._height_min * i : this._height_min * (i - 1) + this._height_max; 
  87. if(oText){ oText._target = (i == index) ? 0 : this._height_text; } 
  88. }) 
  89. this.Move(); 
  90. }, 
  91. //移動(dòng) 
  92. Move: function() { 
  93. clearTimeout(this._timer); 
  94. var bFinish = true;//是否全部到達(dá)目標(biāo)地址 
  95. this.Each(function(oList, oText, i){ 
  96. var iNow = parseInt(oList.style.top), iStep = this.GetStep(oList._target, iNow); 
  97. if (iStep != 0) { bFinish = false; oList.style.top = (iNow + iStep) + "px"; } 
  98. }) 
  99. //未到達(dá)目標(biāo)繼續(xù)移動(dòng) 
  100. if (!bFinish) { var oThis = thisthis._timer = setTimeout(function(){ oThis.Move(); }, this.Time); } 
  101. }, 
  102. //獲取步長 
  103. GetStep: function(iTarget, iNow) { 
  104. var iStep = (iTarget - iNow) / this.Step; 
  105. if (iStep == 0) return 0; 
  106. if (Math.abs(iStep) < 1) return (iStep > 0 ? 1 : -1); 
  107. return iStep; 
  108. }, 
  109. Each:function(fun) { 
  110. for (var i = 0; i < this._count; i++) 
  111. fun.call(thisthis._list[i], (this.Showtext ? this._text[i] : null), i); 
  112. }; 
  113. </script> 
  114. <style type="text/css"
  115. #idGlideView { 
  116. height:314px; 
  117. width:325px; 
  118. margin:0 auto; 
  119. #idGlideView div { 
  120. width:325px; 
  121. height:314px; 
  122. </style> 
  123. </head> 
  124. <body> 
  125. <div id="idGlideView"
  126. <div style="background-color:#006699;"> 鼠標(biāo)移到這里試試看!</div> 
  127. <div style="background-color:#FF9933;"> 鼠標(biāo)移到這里試試看!</div> 
  128. </div> 
  129. <div>http://www.survivalescaperooms.com/</div> 
  130. <SCRIPT> 
  131. var gv = new GlideView("idGlideView", 314, "div", 280,""); 
  132. </SCRIPT> 
  133. </body> 
  134. </html> 



希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 伊宁县| 个旧市| 民丰县| 英德市| 长岭县| 五河县| 会泽县| 承德县| 武功县| 呼和浩特市| 隆回县| 靖州| 榆树市| 蚌埠市| 邹城市| 镇安县| 梁河县| 乐山市| 灵山县| 宁国市| 广灵县| 曲麻莱县| 荃湾区| 建德市| 偏关县| 邵阳县| 滦南县| 禹州市| 军事| 建昌县| 响水县| 宾阳县| 永胜县| 吐鲁番市| 甘南县| 兴安盟| 盈江县| 阜康市| 原阳县| 青海省| 巴彦县|