// 榛樿obj涓烘墽琛屽厓绱 // HOVER // 榛樿鏍峰紡 .h , 榛樿Hover鏍峰紡 .hover // 鑷畾涔塇OVER鍙娇鐢 Hover(obj, classname) $(function(){ $(".h").hover(function(){ $(this).addClass("hover") }, function(){ $(this).removeClass("hover") }) }) function Hover(obj, classname) { obj.hover(function(){ $(this).addClass(classname) }, function(){ $(this).removeClass(classname) }) } // TAB // 榛樿鐒︾偣鏍峰紡 .cur // 涓洪槻姝p绯荤粺opacity鍙兘鍑虹幇鐨勯敮榻挎垨杈圭紭妯$硦锛 榛樿.tabbox鏁堟灉.show() / .hide() // 鎷撳睍.tabbox鎴恛pacity锛 闇€鍦?tabbox涓婂姞涓 data-effect="true" function Tab(tabBtn, tabBox) { var tabbl = true; tabBtn.eq(0).addClass("cur") tabBox.eq(0).show() tabBtn.click(function(){ var n = $(this).index(); $(this).addClass("cur").siblings().removeClass("cur") if(tabBox.attr("data-effect") == "true"){ if(!tabbl){ return } tabbl = false; tabBox.eq(n).stop().fadeIn(800).siblings().stop().fadeOut(800, function(){ tabbl = true; }) }else{ tabBox.eq(n).show().siblings().hide() } }) } // 鍥剧墖鍏ㄥ睆 / 鍥剧墖鍏呮弧鏁翠釜鐖剁骇 // 榛樿box鑷甫loading鑳屾櫙鍥 // 榛樿obj hide function FullBg(box, obj){ box.css("background", "none") obj.eq(0).stop().fadeIn(1000) function resizeBg() { obj.removeClass("w-f").removeClass("h-f").css("margin", 0) var boxR = box.outerWidth() / box.outerHeight(), objR = obj.width() / obj.height(); if( objR < boxR ) { obj.addClass('w-f').css("margin-top", -(obj.height() - box.outerHeight()) / 2); }else{ obj.addClass('h-f').css("margin-left", -(obj.width() - box.outerWidth()) / 2); } } $(window).resize(resizeBg).trigger("resize"); } // 瑙嗛鍏ㄥ睆 / 瑙嗛鍏呮弧鏁翠釜鐖剁骇 (video鑾峰彇瀹介珮鏈夐棶棰? function videoFull(obj, width, height){ var $video = obj function resizeBg() { $video.attr("width", "").attr("height", "").attr("style", "") var boxR = $('.top-video').outerWidth() / $('.top-video').outerHeight(), objR = width / height; if( objR < boxR ) { $video.attr("width", "100%") var videoHeight = $video.width() / objR var top = - (videoHeight - $('.top-video').outerHeight()) / 2 > 0 ? 0 : - (videoHeight - $('.top-video').outerHeight()) / 2 $video.css("margin-top", top); }else{ $video.attr("height", "100%") var videoWidth = $video.height() * objR var left = - (videoWidth - $('.top-video').outerWidth()) / 2 > 0 ? 0 : - (videoWidth - $('.top-video').outerWidth()) / 2 $video.css("margin-left", left); } } $(window).resize(resizeBg).trigger("resize"); } // 鏍囩杩涘満鏁堟灉 // 鐢ㄤ簬澶氬钩绾ф爣绛句緷娆¤浇鍏 榛樿鏍囩鍏锋湁position灞炴€у強opacuty: 0; // direction 浠庡摢涓柟鍚戣繘鍏 // distance 杩涘叆鍒版寚瀹氳窛绂 // number 骞崇骇鏍囩鐨勪釜鏁 // time 杩涘満鍔ㄧ敾鐨勬椂闂 // delay 涓嬩竴鏍囩鐨勫欢杩 // callback 鍥炶皟鍑芥暟 function Enter(obj, direction, distance, number, time, delay, callback) { // 浠庡乏寰€鍙筹紝distance > 0 if(direction == "left"){ obj.stop().animate({ left : distance, opacity : 1 }, time) setTimeout(function(){ if(obj.next().index() != -1){ Enter(obj.next(), direction, distance, number, time, delay, callback) }else{ setTimeout(function(){ callback = callback || function(){}; callback (); return }, time - delay) } }, delay) } // 浠庝笂寰€涓嬶紝distance > 0 if(direction == "top"){ obj.stop().animate({ top : distance, opacity : 1 }, time) setTimeout(function(){ if(obj.next().index() != -1){ Enter(obj.next(), direction, distance, number, time, delay, callback) }else{ setTimeout(function(){ callback = callback || function(){}; callback (); return }, time - delay) } }, delay) } // CSS3 X浣嶇Щ if(direction == "X"){ obj.stop().transition({ x : distance, opacity : 1 }, time) setTimeout(function(){ if(obj.next().index() != -1){ Enter(obj.next(), direction, distance, number, time, delay, callback) }else{ setTimeout(function(){ callback = callback || function(){}; callback (); return }, time - delay) } }, delay) } // CSS3 y浣嶇Щ if(direction == "Y"){ obj.stop().transition({ y : distance, opacity : 1 }, time) setTimeout(function(){ if(obj.next().index() != -1){ Enter(obj.next(), direction, distance, number, time, delay, callback) }else{ setTimeout(function(){ callback = callback || function(){}; callback (); return }, time - delay) } }, delay) } } // 鍥剧墖鍔犺浇 璋冪敤鏂规硶 // _PreLoadImg([ // 鍥剧墖璺緞(鏁扮粍褰㈠紡) // ],function(){ // }) function _PreLoadImg(b,e){var c=0,a={},d=0;for(src in b){d++}for(src in b){a[src]=new Image();a[src].onload=function(){if(++c>=d){e(a)}};a[src].src=b[src]}}; //鍥剧墖鎳掑姞杞 //妫€娴嬪睆骞曟粴鍔ㄦ潯楂樺害 function lazy(){ for (var i = 0; i < $("img").length; i++) { if($($("img")[i]).offset().top-$(window).height()<$(window).scrollTop()){ $("img")[i].src=$("img")[i].dataset["src"]; } } } // $(function(){ // lazy(); // $(window).on("scroll",lazy); // $(window).on("resize",lazy); // })