[JavaScript] js图片旋转焦点图轮播 →→→→→进入此内容的聊天室

来自 , 2020-11-06, 写在 JavaScript, 查看 118 次.
URL http://www.code666.cn/view/68d30a95
  1. function ZoomPic ()
  2. {
  3.         this.initialize.apply(this, arguments) 
  4. }
  5. ZoomPic.prototype =
  6. {
  7.         initialize : function (id)
  8.         {
  9.                 var _this = this;
  10.                 this.wrap = typeof id === "string" ? document.getElementById(id) : id;
  11.                 this.oUl = this.wrap.getElementsByTagName("ul")[0];
  12.                 this.aLi = this.wrap.getElementsByTagName("li");
  13.                 this.prev = this.wrap.getElementsByTagName("pre")[0];
  14.                 this.next = this.wrap.getElementsByTagName("pre")[1];
  15.                 this.timer = null;
  16.                 this.aSort = [];
  17.                 this.iCenter = 2;
  18.                 this._doPrev = function () {return _this.doPrev.apply(_this)};
  19.                 this._doNext = function () {return _this.doNext.apply(_this)};
  20.                 this.options = [
  21.                         {width:476, height:210, top:40, left:0, zIndex:1},
  22.                         {width:426, height:250, top:20, left:50, zIndex:2},
  23.                         {width:654, height:290, top:0, left:150, zIndex:3},
  24.                         {width:426, height:250, top:20, left:480, zIndex:2},
  25.                         {width:476, height:210, top:40, left:476, zIndex:1},
  26.                 ];
  27.                 for (var i = 0; i < this.aLi.length; i++) this.aSort[i] = this.aLi[i];
  28.                 this.aSort.unshift(this.aSort.pop());
  29.                 this.setUp();
  30.                 this.addEvent(this.prev, "click", this._doPrev);
  31.                 this.addEvent(this.next, "click", this._doNext);
  32.                 this.doImgClick();             
  33.                 this.timer = setInterval(function ()
  34.                 {
  35.                         _this.doNext() 
  36.                 }, 3000);              
  37.                 this.wrap.onmouseover = function ()
  38.                 {
  39.                         clearInterval(_this.timer)     
  40.                 };
  41.                 this.wrap.onmouseout = function ()
  42.                 {
  43.                         _this.timer = setInterval(function ()
  44.                         {
  45.                                 _this.doNext() 
  46.                         }, 3000);      
  47.                 }
  48.         },
  49.         doPrev : function ()
  50.         {
  51.                 this.aSort.unshift(this.aSort.pop());
  52.                 this.setUp()
  53.         },
  54.         doNext : function ()
  55.         {
  56.                 this.aSort.push(this.aSort.shift());
  57.                 this.setUp()
  58.         },
  59.         doImgClick : function ()
  60.         {
  61.                 var _this = this;
  62.                 for (var i = 0; i < this.aSort.length; i++)
  63.                 {
  64.                         this.aSort[i].onclick = function ()
  65.                         {
  66.                                 if (this.index > _this.iCenter)
  67.                                 {
  68.                                         for (var i = 0; i < this.index - _this.iCenter; i++) _this.aSort.push(_this.aSort.shift());
  69.                                         _this.setUp()
  70.                                 }
  71.                                 else if(this.index < _this.iCenter)
  72.                                 {
  73.                                         for (var i = 0; i < _this.iCenter - this.index; i++) _this.aSort.unshift(_this.aSort.pop());
  74.                                         _this.setUp()
  75.                                 }
  76.                         }
  77.                 }
  78.         },
  79.         setUp : function ()
  80.         {
  81.                 var _this = this;
  82.                 var i = 0;
  83.                 for (i = 0; i < this.aSort.length; i++) this.oUl.appendChild(this.aSort[i]);
  84.                 for (i = 0; i < this.aSort.length; i++)
  85.                 {
  86.                         this.aSort[i].index = i;
  87.                         if (i < 5)
  88.                         {
  89.                                 this.css(this.aSort[i], "display", "block");
  90.                                 this.doMove(this.aSort[i], this.options[i], function ()
  91.                                 {
  92.                                         _this.doMove(_this.aSort[_this.iCenter].getElementsByTagName("img")[0], {opacity:100}, function ()
  93.                                         {
  94.                                                 _this.doMove(_this.aSort[_this.iCenter].getElementsByTagName("img")[0], {opacity:100}, function ()
  95.                                                 {
  96.                                                         _this.aSort[_this.iCenter].onmouseover = function ()
  97.                                                         {
  98.                                                                 _this.doMove(this.getElementsByTagName("div")[0], {bottom:0})
  99.                                                         };
  100.                                                         _this.aSort[_this.iCenter].onmouseout = function ()
  101.                                                         {
  102.                                                                 _this.doMove(this.getElementsByTagName("div")[0], {bottom:-100})
  103.                                                         }
  104.                                                 })
  105.                                         })
  106.                                 });
  107.                         }
  108.                         else
  109.                         {
  110.                                 this.css(this.aSort[i], "display", "none");
  111.                                 this.css(this.aSort[i], "width", 0);
  112.                                 this.css(this.aSort[i], "height", 0);
  113.                                 this.css(this.aSort[i], "top", 37);
  114.                                 this.css(this.aSort[i], "left", this.oUl.offsetWidth / 2)
  115.                         }
  116.                         if (i < this.iCenter || i > this.iCenter)
  117.                         {
  118.                                 this.css(this.aSort[i].getElementsByTagName("img")[0], "opacity", 100)
  119.                                 this.aSort[i].onmouseover = function ()
  120.                                 {
  121.                                         _this.doMove(this.getElementsByTagName("img")[0], {opacity:100})       
  122.                                 };
  123.                                 this.aSort[i].onmouseout = function ()
  124.                                 {
  125.                                         _this.doMove(this.getElementsByTagName("img")[0], {opacity:100})
  126.                                 };
  127.                                 this.aSort[i].onmouseout();
  128.                         }
  129.                         else
  130.                         {
  131.                                 this.aSort[i].onmouseover = this.aSort[i].onmouseout = null
  132.                         }
  133.                 }              
  134.         },
  135.         addEvent : function (oElement, sEventType, fnHandler)
  136.         {
  137.                 return oElement.addEventListener ? oElement.addEventListener(sEventType, fnHandler, false) : oElement.attachEvent("on" + sEventType, fnHandler)
  138.         },
  139.         css : function (oElement, attr, value)
  140.         {
  141.                 if (arguments.length == 2)
  142.                 {
  143.                         return oElement.currentStyle ? oElement.currentStyle[attr] : getComputedStyle(oElement, null)[attr]
  144.                 }
  145.                 else if (arguments.length == 3)
  146.                 {
  147.                         switch (attr)
  148.                         {
  149.                                 case "width":
  150.                                 case "height":
  151.                                 case "top":
  152.                                 case "left":
  153.                                 case "bottom":
  154.                                         oElement.style[attr] = value + "px";
  155.                                         break;
  156.                                 case "opacity" :
  157.                                         oElement.style.filter = "alpha(opacity=" + value + ")";
  158.                                         oElement.style.opacity = value / 100;
  159.                                         break;
  160.                                 default :
  161.                                         oElement.style[attr] = value;
  162.                                         break
  163.                         }      
  164.                 }
  165.         },
  166.         doMove : function (oElement, oAttr, fnCallBack)
  167.         {
  168.                 var _this = this;
  169.                 clearInterval(oElement.timer);
  170.                 oElement.timer = setInterval(function ()
  171.                 {
  172.                         var bStop = true;
  173.                         for (var property in oAttr)
  174.                         {
  175.                                 var iCur = parseFloat(_this.css(oElement, property));
  176.                                 property == "opacity" && (iCur = parseInt(iCur.toFixed(2) * 100));
  177.                                 var iSpeed = (oAttr[property] - iCur) / 5;
  178.                                 iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
  179.                                
  180.                                 if (iCur != oAttr[property])
  181.                                 {
  182.                                         bStop = false;
  183.                                         _this.css(oElement, property, iCur + iSpeed)
  184.                                 }
  185.                         }
  186.                         if (bStop)
  187.                         {
  188.                                 clearInterval(oElement.timer);
  189.                                 fnCallBack && fnCallBack.apply(_this, arguments)       
  190.                         }
  191.                 }, 30)
  192.         }
  193. };
  194. window.onload = function ()
  195. {
  196.         new ZoomPic("Index_Box");
  197. };

回复 "js图片旋转焦点图轮播"

这儿你可以回复上面这条便签

captcha