;(function ($) { var methods = { /***ajax 鎻愪氦琛ㄥ崟***/ submit: function (options) { if(!this.length || this.hasClass('default-slider-2')){ return false; } var op = options ? options : function(e){}; this.submit(function(){ $.ajax({ url: this.action, type: this.method, data: $(this).serialize(), dataType: "json", success: function(e){ showmessage(e,function(){ op(e.data); }); } }); return false; }); } /***鍏冪礌鐩稿鐖跺厓绱犲瀭鐩村眳涓?**/ ,verticalCenter: function (options) { if(!this.length){ return false; } var op = $.extend({ parentHeight : $_Y['height'], style : 'paddingTop' },options); var $this = this; var $img = $this.find('img'); var imgl = $this.find('img').length; var h; if(imgl > 0){ //鍒ゆ柇鍥剧墖鏈夋病鏈夌紦瀛 $img.each(function(){ if($(this).height()){ imgl--; } else { //鍏煎jQuery 3.7 // $(this).load(function(){ $(this).on('load',function(){ imgl--; }); } }); } else { imgl = 0; h = $this.outerHeight(true); } var t = setInterval(function(){ if(!imgl){ h = $this.outerHeight(true); clearInterval(t); var top = (op.parentHeight-h)/2; $this.css(op.style,top); } },300); } /*** *鍔熻兘锛氬够鐏墖 *娉ㄦ剰浜嬮」锛 * 1銆佽疆鎾厓绱犱竴瀹氭槸閫夋嫨鍣ㄤ笅鐨勭洿灞 'ul > li' ***/ ,slider: function (options) { if(!this.length || this.hasClass('default-slider-2')){ return false; } /*骞荤伅鐗囧厓绱犱笉鍙鎯呭喌涓 绂佹鎵ц*/ if(this.is(":hidden")){ return false; } var op = $.extend({ effect : "show" //show(绉诲姩) fadeIn(娣″叆娣″嚭) ,direction : "right" //left right up down ,linear : "easeInOutQuint" //绾挎€у弬鏁 ,speed : 500 //绉诲姩閫熷害 ,interval : 2000 //鎾斁闂撮殧 ,distance : 0 //鍗曟婊氬姩璺濈 榛樿婊氬姩涓€涓瓙鍏冪礌 ,autoPlay : 1 //鏄惁鑷姩鎾斁 ,hoverStop : 1 //榧犳爣缁忚繃鍥剧墖鏄惁鍋滄鎾斁 ,isSingle : 1 //鏄惁鍗曞紶杞挱妯″紡 ,isButton : 1 //鏄惁鏄剧ず鍓嶅悗鎸夐挳 ,isDots : 1 //鏄惁鏄剧ず鐐 ,isMousewheel : 0 //鏄惁榧犳爣婊氳疆瑙︽帶 ,isThumb : 0 //鏄惁鏄剧ず缂╃暐鍥 ,thumbNum : 3 //鏄惁鏄剧ず缂╃暐鍥 ,thumbHeight : 80 //缂╃暐鍥鹃珮搴 榛樿80 ,thumbWidth : 150 //缂╃暐鍥惧搴 榛樿150 ,thumbOptions : {} }, options); /*瑕嗙洊鍊?/ //濡傛灉閫夋嫨鏄剧ず缂╃暐鍥剧殑璇 灏变笉鑳芥樉绀虹偣 涔熶笉鑷姩鎾斁 if(op.isThumb){ op.isDots = 0; op.autoPlay = 0; } //濡傛灉鏄墜鏈虹増灏卞己鍒 effect 涓 show if($_Y.ismobile || $('body').hasClass('ismobile')){ //$_Y.ismobile = true; //杩欎竴鍙ヤ細褰卞搷鍒 global.js 閲岄潰 rezise 浜嬩欢閲岄潰鑾峰彇涓嶅埌姝g‘鐨 ismobile 鍊 rao 20211018 op.effect = 'show'; } this.html('
'+this.html()+'
'); var $this = this; if($this.children('.default-slider-box').length > 0){ var $box = $this.children('.default-slider-box'); } else { return false; } if($box.children('ul').length > 0){ var $ul = $box.children('ul'); } else { return false; } if($ul.children('li').length > 0){ var $li = $ul.children('li'), liLength = $li.length, thisWidth = $this.width(); thisHeight = $this.height(); } else { return false; } //PC绔笅鏀瑰彉娴忚鍣ㄥぇ灏忥紝骞荤伅鐗囦篃杩涜瀹藉害鍏煎锛堢Щ鍔ㄧ鏃犳晥锛 rao 20211018 $(window).resize(function(){ if(!$_Y.ismobile){ thisWidth = $this.width(); $li.width(thisWidth); } }) //閬嶅巻 li 鑾峰彇鍊 var ulWidth = !$this.hasClass("thumb") ? 0 : $ul.width() //瀹為檯ul 瀹藉害 ,ulHeight = !$this.hasClass("thumb") ? 0 : $ul.height() //瀹為檯ul 瀹藉害 ,maxheight = 0 //鏈€澶х殑li 楂樺害 ,maxwidth = 0 //鏈€澶х殑li 瀹藉害 ,dotshtml = '' //dots 鐨 html ,thumbHtml = '' ,thumbItemHtml = ''; /**鏍规嵁鍙傛暟鍐欐彃鍏 绫?*/ //鐩掔被 $this.addClass('default-slider-2'); //瑕佹妸 -2 鍘绘帀 //妯悜绫 if(op.direction == 'left' || op.direction == 'right'){ $this.addClass('default-slider-direction-left'); //濡傛灉鏁堟灉涓虹Щ鍔 if(op.effect == 'show'){ $ul.addClass('cl'); } } if(op.isSingle){ $this.addClass('default-slider-single'); if(op.direction == 'left' || op.direction == 'right'){ $li.width(thisWidth); } else if(op.direction == 'up' || op.direction == 'down') { $li.width(thisHeight); } } //$('img').lazyload(); $li.each(function(index){ //妯悜 show 鑾峰彇鎬诲搴 var $thisLi = $(this); if(op.isSingle){ //$li.find('img').css({'marginLeft':-($(this).find('img').width()/2)}); if($thisLi.find('img').height() > 0){ $thisLi.find('img').css({'marginLeft':-($thisLi.find('img').width()/2)}); } else { // 鍏煎 jQuery 3.7 // $thisLi.find('img').load(function(){ $thisLi.find('img').on('load',function(){ $thisLi.find('img').css({'marginLeft':-($thisLi.find('img').width()/2)}); if(op.direction == 'left' || op.direction == 'right'){ maxheight = Math.max(maxheight, $thisLi.outerHeight(true)); $ul.css({height:maxheight}); } }); } } if(!$this.hasClass("thumb") && op.effect == 'show' && (op.direction == 'left' || op.direction == 'right')){ ulWidth += $thisLi.outerWidth(true); } else if(!$this.hasClass("thumb") && (op.direction == 'up' || op.direction == 'down')){ ulHeight += $thisLi.outerHeight(true); } // 鏁堟灉涓 fadeIn 璁剧疆绗竴寮犲彲瑙佸拰璁剧疆鐩掑瓙涓烘渶楂 li 楂樺害 if(op.effect == 'fadeIn'){ if(index == 0){ $thisLi.css({display:'block'}); } } if(op.direction == 'left' || op.direction == 'right'){ maxheight = Math.max(maxheight, $thisLi.outerHeight(true)); } if(op.direction == 'up' || op.direction == 'down'){ maxwidth = Math.max(maxwidth, $thisLi.outerWidth(true)); } //濡傛灉鏄剧ず鐐瑰苟涓旈粯璁ょЩ鍔ㄥ崟浣 if(op.isDots && !op.distance){ var dotclass = (index == 0) ? 'class="active"' : ''; dotshtml += ''+(index+1)+''; } //濡傛灉鏄剧ず缂╃暐鍥 if(op.isThumb){ var dataOriginal = $thisLi.find('img').attr('_src'); thumbItemHtml += '
  • '; } }); //濡傛灉妯悜 if(op.direction == 'left' || op.direction == 'right'){ $ul.css({height:maxheight}); //濡傛灉鏁堟灉涓虹Щ鍔 if(op.effect == 'show'){ if(ulWidth < thisWidth){ $ul.css({width:Math.ceil(thisWidth/ulWidth)*ulWidth*2}); var _ulHtml = ''; for(i=1;i<=Math.ceil(thisWidth/ulWidth);i++){ _ulHtml += $box.children('ul').html(); } $ul.html(_ulHtml); $ul.css({width:ulWidth*Math.ceil(thisWidth/ulWidth)*2}); } else { $ul.css({width:ulWidth*2}); } } } else if(op.direction == 'up' || op.direction == 'down'){ op.effect = 'show'; $ul.css({width:maxwidth}); if(ulHeight < thisHeight){ $ul.css({height:Math.ceil(thisHeight/ulHeight)*ulHeight*2}); var _ulHtml = ''; for(i=1;i<=Math.ceil(thisHeight/ulHeight);i++){ _ulHtml += $box.children('ul').html(); } $ul.html(_ulHtml); $ul.css({height:ulHeight*Math.ceil(thisHeight/ulHeight)*2}); } else { $ul.css({height:ulHeight*2}); } } //鐢ㄤ簬鎻掑叆 var ulHtml = $($box.children('ul').html()); //杩欎竴鍙ヨ娉ㄦ剰涓 鐪嬫槸涓嶆槸闇€瑕侀噸鏂版鏌 $li = $ul.children('li'); //濡傛灉娣″叆娣″嚭 //璁剧疆 ul 鐨勯珮搴 璨屼技 搴旇杩樻湁鍏朵粬鏉′欢鍙互婊¤冻 if(op.effect == 'fadeIn'){ $this.addClass('default-slider-effect-fadeIn'); } //濡傛灉鏄剧ず鎸夐挳 if(op.isButton){ $this.append(''); } //濡傛灉鏄剧ず鐐 if(op.isDots){ if(op.distance){ dotshtml += '1'; if(op.direction == 'left' || op.direction == 'right'){ dotsunm = Math.ceil(ulWidth/op.distance); } else if(op.direction == 'up' || op.direction == 'down'){ dotsunm = Math.ceil(ulHeight/op.distance); } for(i=2;i<=dotsunm;i++){ dotshtml += ''+i+''; } } $this.append('
    '+dotshtml+'
    '); } //濡傛灉鏄剧ず缂╃暐鍥 if(op.isThumb){ thumbHtml = '
    '; $this.append(thumbHtml); var $thumb = $this.children('.thumb'); //var $thumbBox = $thumb.children(''); op.thumbNum = liLength < op.thumbNum ? $li.length : op.thumbNum; var thumbLiwidth = $thumb.children('ul').children('li').outerWidth(true)+op.thumbWidth-($thumb.children('ul').children('li').find('img').width()); var thumbWidth = thumbLiwidth*op.thumbNum; $thumb.width(thumbWidth); $thumb.children('ul').width(thumbLiwidth*liLength); $thumb.css({'marginLeft':-((thumbWidth/2)+15)}); /* if(op.thumbNum < li.length){ thumb.append(''); } */ //缂╃暐鍥惧够鐏墖 var thumbSliderData = $.extend({ effect : "show" //show(绉诲姩) fadeIn(娣″叆娣″嚭) ,direction : op.direction //left right up down ,linear : op.linear //绾挎€у弬鏁 ,speed : op.speed //绉诲姩閫熷害 ,interval : 3000 //鎾斁闂撮殧 //,distance : thumbWidth ,isSingle : 0 //鏄惁鍗曞紶杞挱妯″紡 ,isDots : 0 //鏄惁鏄剧ず鐐 ,isThumb : 0 //鏄惁鏄剧ず缂╃暐鍥 }, op.thumbOptions); $thumb.taiduyun('slider',thumbSliderData); } var direction = op.direction; //鑷姩鎾斁 if(op.autoPlay){ var autoplay = setInterval(_left(direction),op.interval); } //宸︾偣鍑讳簨浠 $this.find('.prev').click(function(){ clearInterval(autoplay); left('left'); direction = 'left'; }); //鍙崇偣鍑讳簨浠 $this.find('.next').click(function(){ clearInterval(autoplay); direction = 'right'; left(direction); }); //榧犳爣婊氳疆浜嬩欢 if(op.isMousewheel){ $this.bind('mousewheel', function(event, delta){ if(delta < 0){ $this.find('.next').click(); } else { $this.find('.prev').click(); } }); } //鎵嬫満绔粦鍔ㄥ够鐏墖浜嬩欢 var touch_i = 0; var touch_distance = 0; //寮€濮嬫粦灞 if(window.addEventListener){ $this[0].addEventListener('touchstart',function( e ){ touch_i = e.targetTouches[0].clientX; clearInterval(autoplay); },false); //婊戝睆杩囩▼ $this[0].addEventListener('touchmove',function( e ){ touch_distance = e.targetTouches[0].clientX - touch_i; if(touch_distance < -10 || touch_distance > 10){ e.preventDefault(); } else { e.returnValue = true; } },false); //婊戝睆缁撴潫 $this[0].addEventListener('touchend',function( e ){ if(touch_distance > 30){ console.log(touch_distance); left('left'); } else if (touch_distance < 30) { console.log(touch_distance); left('right'); } if(op.autoPlay){ autoplay = setInterval(_left(direction),op.interval); } },false); } //缁忚繃楂樹寒鐐 $this.children('.dots').children('span').mouseover(function(){ clearInterval(autoplay); var toindex = $(this).index(); left(direction,toindex); }); //缁忚繃鐩掑瓙 $this.hover(function(){ if(op.hoverStop){ clearInterval(autoplay); } },function(){ if(op.autoPlay){ autoplay = setInterval(_left(direction),op.interval); } }); //鐐瑰嚮缂╃暐鍥句簨浠 $this.on('click','.thumb ul li',function(){ left(direction,$(this).index()%$li.length); }); //灏佽绉诲姩鍑芥暟缁欒鏃跺櫒浼犲弬 function _left(_name){ return function(){ left(_name); } } //妯悜绉诲姩鍑芥暟 function left(direction,toindex){ var active,actionLi; $ul = $box.children('ul'); $li = $ul.children('li'); setTimeout(function(){ $li.find('img').lazyload(); },300); if(op.effect == 'show'){ if(direction == 'left' || direction == 'right'){ var thisLeft = $box.offset().left ,ulLeft = $ul.offset().left ,ulMarginLeft = parseInt($ul.css('marginLeft')); } else { //鍚戜笂 var thisTop = $box.offset().top ,ulTop = $ul.offset().top ,ulMarginTop = parseInt($ul.css('marginTop')); } if(typeof(toindex)=="undefined" && direction == 'left' && ulMarginLeft >= 0){ prevWidth = $li.last().outerWidth(true); $ul.prepend(ulHtml); $ul.css({'marginLeft':-(ulWidth)}); ulMarginLeft = ulMarginLeft-ulWidth; $ul = $box.children('ul'); $li = $ul.children('li'); } else if ((typeof(toindex) != "undefined" && (direction == 'right' || direction == 'left')) || (direction == 'right' && $li.last().offset().left <= thisLeft+thisWidth)){ $ul.append(ulHtml); if(typeof(toindex) != "undefined"){ if(op.distance){ $ul.stop().animate({marginLeft:-((op.distance-1)*toindex)+'px'},op.speed,op.linear); } else { $ul.stop().animate({marginLeft:-($li.eq(toindex).offset().left-ulLeft)+'px'},op.speed); } $this.children('.dots').children('span').eq(toindex).addClass('active').siblings().removeClass('active'); return false; } if(ulMarginLeft <= -ulWidth){ ulMarginLeft = ulMarginLeft + ulWidth; } $ul = $box.children('ul'); $li = $ul.children('li'); $ul.css({'marginLeft':ulMarginLeft+'px'}); } else if (typeof(toindex) != "undefined" || (direction == 'up' && ($li.last().offset().top <= (thisTop+thisHeight)))){ $ul.append(ulHtml); if(typeof(toindex) != "undefined"){ if(op.distance){ $ul.stop().animate({marginTop:-((op.distance-1)*toindex)+'px'},op.speed,op.linear); } else { $ul.stop().animate({marginTop:-($li.eq(toindex).offset().top-ulTop)+'px'},op.speed); } $this.children('.dots').children('span').eq(toindex).addClass('active').siblings().removeClass('active'); return false; } if(ulMarginTop <= -ulHeight){ ulMarginTop = ulMarginTop + ulHeight; } $ul = $box.children('ul'); $li = $ul.children('li'); $ul.css({'marginTop':ulMarginTop+'px'}); } $li.each(function(index){ if(direction == 'left' || direction == 'right'){ if(op.isSingle && $(this).find('img').css("marginLeft") == '0px'){ $(this).find('img').css({"marginLeft":-($(this).find('img').width()/2)}); } thisLiLeft = $(this).offset().left; thisLiWidth = $(this).outerWidth(true); } else { //鍚戜笂 if(op.isSingle && $(this).find('img').css("marginTop") == '0px'){ $(this).find('img').css({"marginTop":-($(this).find('img').height()/2)}); } thisLiTop = $(this).offset().top; thisLiHeight = $(this).outerHeight(true); } if(direction == 'left'){ if(thisLiLeft+thisLiWidth > thisLeft){ if(op.distance){ var oldactive = $this.children('.dots').children('span.active'); if(oldactive.index() == 0){ $this.children('.dots').children('span').last().addClass('active').siblings().removeClass('active'); } else { oldactive.removeClass('active').prev().addClass('active'); } $ul.stop().animate({marginLeft:(ulMarginLeft+op.distance)+'px'},op.speed,op.linear); $(this).click(); } else { prevWidth = $(this).prev().outerWidth(true); active = (index >= liLength) ? (index-liLength) :index ; active = (active == 0) ? liLength-1 : active-1; $this.children('.dots').children('span').eq(active).addClass('active').siblings().removeClass('active'); $ul.stop().animate({marginLeft:(ulMarginLeft+prevWidth)+'px'},op.speed,op.linear); $(this).click(); } return false; } } else if(direction == 'right'){ if(thisLiLeft >= thisLeft+thisWidth){ if(op.distance){ var oldactive = $this.children('.dots').children('span.active'); if(oldactive.index() == $this.children('.dots').children('span').length-1){ $this.children('.dots').children('span').first().addClass('active').siblings().removeClass('active'); } else { oldactive.removeClass('active').next().addClass('active'); } $ul.stop().animate({marginLeft:(ulMarginLeft-op.distance)+'px'},op.speed,op.linear); $(this).click(); } else { active = index >= liLength ? index%liLength : index; $this.children('.dots').children('span').eq(active).addClass('active').siblings().removeClass('active'); $ul.stop().animate({marginLeft:(ulMarginLeft-$(this).outerWidth(true))+'px'},op.speed,op.linear); $(this).click(); } return false; } }else if(direction == 'up'){ if(thisLiTop >= thisTop+thisHeight){ if(op.distance){ var oldactive = $this.children('.dots').children('span.active'); if(oldactive.index() == $this.children('.dots').children('span').length-1){ $this.children('.dots').children('span').first().addClass('active').siblings().removeClass('active'); } else { oldactive.removeClass('active').next().addClass('active'); } $ul.stop().animate({marginTop:(ulMarginTop-op.distance)+'px'},op.speed,op.linear); $(this).click(); } else { active = index >= liLength ? index%liLength : index; $this.children('.dots').children('span').eq(active).addClass('active').siblings().removeClass('active'); $ul.stop().animate({marginTop:(ulMarginTop-$(this).outerHeight(true))+'px'},op.speed,op.linear); $(this).click(); } return false; } } }); } else if(op.effect == 'fadeIn') { if(typeof(toindex) != "undefined"){ $actionLi = $li.eq(toindex); active = toindex; } else { $li.each(function(index){ if(!$(this).is(":hidden")){ if( direction == 'left' ){ $actionLi = index == 0 ? actionLi = $li.last() :$ (this).prev(); active = (index == 0) ? liLength-1 : index-1; } else if( direction == 'right' ){ $actionLi = index == liLength-1 ? actionLi = $li.first() : actionLi = $(this).next(); active = (index == liLength-1) ? 0 : index+1; } return false; } }); } //褰撳墠鏄剧ず鐨勫厓绱犲姞 active_b 绫 $actionLi.fadeIn(op.speed).addClass('active_b').siblings().removeClass('active_b').fadeOut(op.speed); $this.children('.dots').children('span').eq(active).addClass('active').siblings().removeClass('active'); } } } ,init: function(){ alert('璇峰~鍐 taiduyun 鐨勭涓€涓弬鏁颁负鎸囧畾鏂规硶'); } }; $.fn.taiduyun = function (method) { // 鏂规硶璋冪敤 if (methods[method]) { return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || !method) { return methods.init.apply(this, arguments); } else { $.error('Method ' + method + ' does not exist on jQuery.tooltip 锛? + method + ' 鏂规硶涓嶅瓨鍦級'); } }; })(jQuery);