1(function ($, window) { 2 /** é»è®¤é ç½® */ 3 var defaults = { 4 //æ¯ä¾ 5 ratio: 'auto', 6 //ææ¾ææ 7 style: 'fade', 8 //ææ¾é度 9 speend: 5, 10 //æ¯å¦èªå¨ææ¾ 11 autoplay: 1, 12 //æ¯å¦æ¾ç¤ºä¸ä¸ç¿»é¡µæé® 13 showcotrols: 1, 14 //æåä½ç½®(0:åºé¨ï¼1:é¡¶é¨) 15 captionpos: 0, 16 //èåç±»å(0:æ ,1:æå,2:å°å¾) 17 navstyle: 0, 18 //èåä½ç½®(0:åºé¨,1:é¡¶é¨,2:左边,3:å³è¾¹) 19 navlocation: 0, 20 //ç¦ç¨äºä»¶ 21 disabled: false 22 }; 23 function slide(element, options) { 24 this.element = element; 25 this.$element = $(element); 26 this.$items = null; 27 this.curIndex = 0; 28 this.options = $.extend({}, defaults, options); 29 this.playtime = null; 30 this.allimg = null; 31 this.imginfo = []; 32 this.curheight = 0; 33 this.curSubIndex = 0; 34 this._init(); 35 } 36 slide.prototype = { 37 //åå§å 38 _init: function () { 39 this.$items = this.$element.find('div.slide-item'); 40 this._setShowCotrols(); 41 this._setCaptionPos(); 42 this._setNavigation(); 43 this._initSize(); 44 if (!this.options.disabled) 45 this._initEvent(); 46 this._autoPlay(); 47 }, 48 //åå§æ¯ä¾ 49 _initSize: function () { 50 var self = this; 51 this.allimg = this.$element.find('div.slide-item img'); 52 var count = 1; 53 //å è½½å¾ç 54 for (var i = 0; i < this.allimg.length; i++) { 55 var temImg = $(this.allimg[i]); 56 var newImg = new Image; 57 newImg.index = i; 58 newImg.onload = function () { 59 var index = parseInt(this.index); 60 self.imginfo[self.imginfo.length] = {'index': index, 'width': this.width, 'height': this.height}; 61 if (count == self.allimg.length) 62 self._setSize(); 63 if (index > 0) 64 $(self.$items[index]).hide(); 65 count++; 66 }; 67 newImg.src = temImg.attr('src'); 68 } 69 }, 70 //äºä»¶ 71 _initEvent: function () { 72 var self = this; 73 var prev = this.$element.find('div.cycle-prev:first'); 74 var next = this.$element.find('div.cycle-next:first'); 75 prev.click(function () { 76 if ($(this).data('play') == '1') { 77 return ''; 78 } else { 79 $(this).data('play', '1'); 80 } 81 self._stopPlay(); 82 var index = self.curIndex - 1; 83 if (index < 0) 84 index = self.$items.length - 1; 85 self._play(index); 86 self._add_active(index); 87 self._autoPlay(); 88 return false; 89 }); 90 next.click(function () { 91 if ($(this).data('play') == '1') { 92 return ''; 93 } else { 94 $(this).data('play', '1'); 95 } 96 self._stopPlay(); 97 var index = self.curIndex + 1; 98 if (index > self.$items.length - 1) 99 index = 0; 100 self._play(index); 101 self._add_active(index); 102 self._autoPlay(); 103 return false; 104 }); 105 }, 106 //设置æ¯ä¾ 107 _setSize: function () { 108 var maxWith = this.$element.width(); 109 var maxHeight = 0; 110 if (this.options.ratio != 'auto') { 111 var ratioItems = this.options.ratio.split(':'); 112 var ratioWidth = parseInt(ratioItems[0]); 113 var ratioHeight = parseInt(ratioItems[1]); 114 maxHeight = parseInt((maxWith / ratioWidth) * ratioHeight); 115 } 116 117 for (var i = 0; i < this.allimg.length; i++) { 118 var temImg = $(this.allimg[i]); 119 var temImgInfo = null; 120 for (var j = 0; j < this.imginfo.length; j++) { 121 if (i == this.imginfo[j].index) { 122 temImgInfo = this.imginfo[j]; 123 } 124 } 125 var imgWidth = temImgInfo.width; 126 var imgHeight = temImgInfo.height; 127 if (imgWidth > maxWith) { 128 imgHeight = imgHeight * (maxWith / imgWidth);
129 imgWidth = maxWith; 130 } 131 if (this.options.ratio == 'auto') { 132 maxHeight = imgHeight > maxHeight ? imgHeight : maxHeight; 133 maxHeight = parseInt(maxHeight); 134 } else { 135 if (imgHeight > maxHeight) { 136 imgWidth = imgWidth * (maxHeight / imgHeight); 137 imgHeight = maxHeight; 138 imgWidth = parseInt(imgWidth); 139 } 140 } 141 temImg.css({'width': imgWidth}); 142 temImg.parent().css({'width': imgWidth, 'left': (0 - parseInt(imgWidth / 2)), 'top': (0 - parseInt(imgHeight / 2))}); 143 } 144 this.$element.find('.w-slide-content').css('height', maxHeight); 145 this._setNavigation(); 146 }, 147 //èªå¨ææ¾ 148 _autoPlay: function () { 149 if (this.options.autoplay == 1) { 150 var self = this; 151 //setTimeout/setInterval 152 this.playtime = window.setInterval(function () { 153 self._play(); 154 var autoIndex; 155 if (self.curIndex + 1 >= self.$items.length) { 156 autoIndex = 0; 157 } else { 158 autoIndex = self.curIndex + 1; 159 } 160 self._add_active(autoIndex); 161 }, self.options.speend * 1000); 162 163 } 164 }, 165 //åæ¢ææ¾ 166 _stopPlay: function () { 167 if (this.options.autoplay == 1) { 168 if (this.playtime != null) 169 window.clearInterval(this.playtime); 170 171 } 172 }, 173 //å ³éèªå¨ææ¾ 174 _closeAutoPlay: function () { 175 if (this.playtime != null) { 176 clearInterval(this.playtime); 177 this.playtime = null; 178 } 179 }, 180 _getNextIndex: function (index) { 181 var nextIndex = 0; 182 if (typeof index == 'number') { 183 nextIndex = index; 184 return index; 185 } else { 186 if (this.curIndex >= this.$items.length - 1) { 187 nextIndex = 0; 188 } else { 189 nextIndex = this.curIndex + 1; 190 } 191 } 192 return nextIndex; 193 }, 194 //ææ¾ 195 _play: function (index) { 196 var self = this; 197 var nextIndex = this._getNextIndex(index); 198 //æ¸æ¾ææfade 199 if (this.options.style == 'fade') { 200 $(this.$items[this.curIndex]).fadeOut(function () { 201 self.curIndex = nextIndex; 202 $(self.$items[self.curIndex]).fadeIn('fast'); 203 // æ¹åç¹å»ç¶æ 204 self._elementPaly(self); 205 }); 206 } 207 //左峿»å¨ææ 208 if (this.options.style == 'slide') { 209 var maxWith = this.$element.width(); 210 if(this.curIndex !== nextIndex){ 211 $(this.$items[this.curIndex]).animate({'left': (0 - maxWith)}, 500, function () { 212 $(this).hide().css('left', 0); 213 }); 214 $(this.$items[nextIndex]).css('left', maxWith).show(); 215 $(this.$items[nextIndex]).animate({'left': 0}, 500, function () { 216 self.curIndex = nextIndex; 217 // æ¹åç¹å»ç¶æ 218 self._elementPaly(self); 219 }); 220 } 221 } 222 //å¡çå¼åç¾å¶çªææ 223 if (this.options.style == 'fold' || this.options.style == 'slice') { 224 var temCurItem = $(this.$items[this.curIndex]); 225 temCurItem.css('z-index', 1); 226 this.curIndex = nextIndex; 227 // $(this.$items[this.curIndex]).hide(); 228 var curItem = $(this.$items[nextIndex]) 229 curItem.css('z-index', 2); 230 var curImg = curItem.find('.slide-img'); 231 curImg.css('opacity', 0); 232 curItem.show(); 233 var curImgDiv = $(curItem.find('.slide-item-div-inner')); 234 var curWidth = curImgDiv.width(); 235 var curHeight = curImgDiv.height(); 236 var subWidth = curWidth / 12; 237 var html = '<div class="slide-img-block">'; 238 var imgurl = curItem.find('img').attr('src'); 239 for (var i = 0; i < 12; i++) { 240 html += '<div style="'; 241 if (this.options.style == 'fold') { 242 html += 'width:0px;left:' + (subWidth * i) + 'px;' 243 } else if (this.options.style == 'slice') { 244 html += 'width:' + subWidth + 'px;left:' + (subWidth * i) + 'px;'; 245 } 246 html += 'opacity:0;position:absolute;top:0;height:' + curHeight + 'px;overflow:hidden;">'; 247 html += '<img src="' + imgurl + '" style="width:' + curWidth + 'px;top:0;left:-' + (subWidth * i) + 'px;position:absolute;dispaly:block;max-width:none;" /></div>'; 248 } 249 html += "</div>"; 250 curImgDiv.append(html); 251 var count = 0; 252 var itemList = curItem.find('.slide-img-block').children();
253 if (this.options.style == 'fold') { 254 itemList.each(function () { 255 $(this).animate({'width': subWidth, 'opacity': 1}, count * 100, function () { 256 var index = itemList.index($(this)); 257 if (index == itemList.length - 1 && temCurItem.css('z-index') != 2) { 258 curImg.css('opacity', 1); 259 temCurItem.fadeOut(); 260 curItem.find('.slide-img-block').remove(); 261 } 262 }); 263 count++; 264 }); 265 } else if (this.options.style == 'slice') { 266 this.curSubIndex = 0; 267 // this._sliceAction(itemList, subWidth, curImg, curItem, temCurItem); 268 itemList.each(function () { 269 var index = itemList.index($(this)); 270 $(this).animate({'opacity': 1}, count * 150, function () { 271 if (itemList.index($(this)) == itemList.length - 1 && temCurItem.css('z-index') != 2) { 272 curImg.css('opacity', 1); 273 temCurItem.fadeOut(); 274 curItem.find('.slide-img-block').remove(); 275 } 276 }); 277 count++; 278 }); 279 } 280 setTimeout(function () { 281 self._elementPaly(self); 282 }, count * 150); 283 284 } 285 }, 286 _elementPaly: function (self) { 287 // æ¹åç¹å»ç¶æ 288 self.$element.find(".cycle-prev").data("play", '0'); 289 self.$element.find(".cycle-next").data("play", '0'); 290 self.$element.find(".slide-page>a").each(function () { 291 if ($(this).data("play") === '1') { 292 $(this).data("play", "0"); 293 } 294 }); 295 }, 296 _sliceAction: function (items, width, curImg, curItem, temCurItem) { 297 var self = this; 298 if (this.curSubIndex >= items.length - 1) { 299 curImg.css('opacity', 1); 300 temCurItem.hide(); 301 curItem.find('.slide-img-block').remove(); 302 return false; 303 } 304 var item = $(items[this.curSubIndex]); 305 item.animate({'opacity': 1}, 50, function () { 306 self.curSubIndex++; 307 self._sliceAction(items, width, curImg, curItem, temCurItem); 308 }); 309 }, 310 //设置æåä½ç½® 311 _setCaptionPos: function () { 312 var subElement = this.$element.children().get(0); 313 if (this.options.captionpos == 1) { 314 $(subElement).addClass('slide-caption-top'); 315 } else { 316 $(subElement).removeClass('slide-caption-top'); 317 } 318 }, 319 //设置å页æé®æ¯å¦æ¾ç¤º 320 _setShowCotrols: function () { 321 var prev = this.$element.find('div.cycle-prev:first'); 322 var next = this.$element.find('div.cycle-next:first'); 323 if (this.options.showcotrols == 1) { 324 prev.show(); 325 next.show(); 326 } else { 327 prev.hide(); 328 next.hide(); 329 } 330 }, 331 //设置å½åå¯¼èª 332 _add_active: function (index) { 333 var pagest = this.$element.find('.slide-page').children('a'); 334 pagest.eq(index).siblings('a').removeClass('active'); 335 pagest.eq(index).addClass('active'); 336 337 }, 338 //è®¾ç½®å¯¼èª 339 _setNavigation: function () { 340 var nav = this.$element.find('.slide-page'); 341 if (nav.length > 0) 342 nav.remove(); 343 if (this.options.navstyle > 0) { 344 var self = this; 345 var subElement = $(this.$element.children().get(0)); 346 var posElement = $(subElement.children().get(0)) 347 if (this.options.captionpos == 1) { 348 var _w_slide_img = "w-slide-page-img slide-caption-top"; 349 var _w_slide_num = "w-slide-page-num slide-caption-top"; 350 } else { 351 var _w_slide_img = "w-slide-page-img"; 352 var _w_slide_num = "w-slide-page-num"; 353 } 354 var className = (this.options.navstyle == 1 ? _w_slide_num : _w_slide_img); 355 subElement.attr('class', className); 356 className = ''; 357 var navBox = $(this._getNavHtml()); 358 if (!this.options.disabled) { 359 navBox.find('a').each(function () { 360 $(this).on('click', function () { 361 if ($(this).data('play') == '1') { 362 return ''; 363 } else { 364 $(this).data('play', '1'); 365 } 366 self._stopPlay(); 367 self._play(parseInt($(this).attr('data-index'))); 368 self._add_active(parseInt($(this).attr('data-index'))); 369 self._autoPlay(); 370 return false; 371 }) 372 }); 373 } 374 posElement.append(navBox); 375 var slideContent = $(this.$element.find('.w-slide-content:first')); 376 switch (this.options.navlocation) { 377 case 0: 378 className = 'w-page-bottom'; 379 break; 380 case 1: 381 className = 'w-page-top'; 382 break; 383 case 2: 384 className = 'w-page-left'; 385 break; 386 case 3: 387 className = 'w-page-right'; 388 break; 389 } 390 switch (this.options.navlocation) { 391 case 0: 392 case 1: 393 var widthSlide = slideContent.outerWidth(true); 394 var allImg = navBox.find('img'); 395 if (allImg.length * 80 > widthSlide) { 396 var itemWidth = widthSlide / allImg.length; 397 allImg.css('width', itemWidth - 10); 398 } 399 break; 400 case 2: 401 case 3: 402 var heightSlide = slideContent.outerHeight(true); 403 var allImg = navBox.find('img'); 404 if (allImg.length * 80 > heightSlide) { 405 var itemHeight = heightSlide / allImg.length; 406 allImg.css('height', itemHeight - 10);
407 } 408 break; 409 } 410 posElement.attr('class', className); 411 } 412 }, 413 _getNavHtml: function () { 414 var html = '<div class="slide-page">'; 415 var imgCount = this.$items.length; 416 for (var i = 0; i < imgCount; i++) { 417 if (this.options.navstyle == 1) { 418 if (i === this.curIndex) { 419 html += '<a href="javascript:void(0);" data-index="' + i + '" class="active"> ' + (i + 1) + ' </a>'; 420 } else { 421 html += '<a href="javascript:void(0);" data-index="' + i + '"> ' + (i + 1) + ' </a>'; 422 } 423 } else if (this.options.navstyle == 2) { 424 var item = $(this.$items[i]); 425 item = item.find('img.slide-img'); 426 if (i === this.curIndex) { 427 html += '<a href="javascript:void(0)" data-index="' + i + '" class="active"><img src="' + item.attr('src') + '"></a>'; 428 } else { 429 html += '<a href="javascript:void(0)" data-index="' + i + '"><img src="' + item.attr('src') + '"></a>'; 430 } 431 } 432 } 433 html += '</div>'; 434 return html; 435 }, 436 //é ç½® 437 option: function (key, value) { 438 if (typeof (this.options[key]) == 'number') 439 value = parseInt(value); 440 this.options[key] = value; 441 if (key == 'ratio') 442 this._setSize(); 443 if (key == 'autoplay' || key == 'speend') { 444 this._closeAutoPlay(); 445 this._autoPlay(); 446 } 447 if (key == 'showcotrols') 448 this._setShowCotrols(); 449 if (key == 'navstyle' || key == 'navlocation') 450 this._setNavigation(); 451 this._setCaptionPos(); 452 return this.options[key]; 453 } 454 }; 455 /** å°è£ */ 456 $.fn.slide = function (options) { 457 var args = arguments; 458 if (options === undefined || typeof options === 'object') { 459 return this.each(function () { 460 if (!$.data(this, 'slide')) { 461 $.data(this, 'slide', new slide(this, options)); 462 } 463 }); 464 } else if (typeof options === 'string' && options[0] !== '_') { 465 return this.each(function () { 466 var instance = $.data(this, 'slide'); 467 if (instance instanceof slide && typeof instance[options] === 'function') { 468 instance[options].apply(instance, Array.prototype.slice.call(args, 1)); 469 } 470 //æ¸ é¤ç¼å 471 if (options === 'destroy') { 472 $.data(this, 'slide', null); 473 } 474 }); 475 } 476 }; 477}(jQuery, window)); 478 479// 夿å¾çå è½½ç彿° 480function isImgLoad(callback) { 481 var isLoad = true; 482 $('.g-cover').each(function () { 483 if ($(this).height() === 0) { 484 isLoad = false; 485 } 486 }); 487 if (isLoad) { 488 callback(); 489 // 为falseï¼å 为æ¾å°äºæ²¡æå è½½å®æçå¾ï¼å°è°ç¨å®æ¶å¨éå½ 490 } else { 491 var t_img; 492 t_img = setInterval(function () { 493 clearInterval(t_img); 494 isImgLoad(callback); 495 }, 100); 496 } 497} 498 499// 夿å¾çå è½½ç彿° 500var allIsImgLoad = function (_obj, callBack) { 501 var imgLoad = new Array; 502 _obj.each(function (key) { 503 $(this).on('load', function () { 504 imgLoad[key] = true; 505 if (imgLoad.length == _obj.length) { 506 callBack(); 507 } 508 }); 509 if (window.navigator.userAgent.indexOf("Chrome/42.0") > 0) { 510 var src = $(this).attr("src") + "?" + Date.parse(new Date()); 511 } else { 512 var src = $(this).attr("src"); 513 } 514 $(this).attr("src", src); 515 });
vendor: 1 bytes, line 516
516}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.