$(function(){ 'use strict'; // * 婊氬姩鏉 // ----------------------------------------------------------------------- // 绾靛悜閫氱敤 function verticalScroll(scrollname){ if($(scrollname).length > 0) { $(scrollname).mCustomScrollbar({ scrollbarPosition: "outside", theme:"my-theme" }); } } verticalScroll('[data-scroll="vertical-scrollable"]'); // 妯悜閫氱敤 function horizontalScroll(scrollname){ if($(scrollname).length > 0) { $(scrollname).mCustomScrollbar({ scrollbarPosition: "inside", axis:"x", theme:"my-theme-h" }); } } horizontalScroll('[data-scroll="horizontal-scrollable"]'); // 婵€娲荤姸鎬 // ----------------------------------------------------------------------- // 鏈変笖鍙湁涓€涓婵€娲 function activeCurrent(target) { $(target).each(function(){ var $this = $(this); var $targetLink = $this.find('[data-role="activeTarget"]'); $targetLink.each(function(){ var $this = $(this); $this.click(function(){ $targetLink.removeClass('active'); $this.addClass('active'); }); }); }); } activeCurrent('[data-action="activeCurrent"]'); // 鍚屾椂澶氫釜琚縺娲 function toggleClass(target){ $(target).bind('click', function(){ $(this).toggleClass('active'); }); } toggleClass('[data-action="toggleClass"]'); // 婊戣繃鏄剧ず`tooltip` // ----------------------------------------------------------------------- function tooltip(){ var $target = $('[data-role="tooltip"]'); var top = 'tooltip-up', right = 'tooltip-right', bottom = 'tooltip-down', left = 'tooltip-left'; // 鏂瑰悜鏍峰紡 $target.each(function(){ var $tooltip = $( // 涓€瀹氳鍐欏湪閬嶅巻閲岄潰 ''+ '
'+ ''+ '
' ); var $this = $(this), oriation = $this.data('oriation'), // 鏂瑰悜 specialClass = $this.data('special'), // 鐗规畩鏍峰紡 multiClass = 'multiclass', // 澶嶆潅鍐呭姘旀场鏍峰紡 multi = $this.data('multi'), // 鏄惁澶嶆潅鍐呭 interact = $this.data('interact'); // 鏄惁鑳戒氦浜 // 瀹氫綅 function locate(targetTrigger, targetTooltip){ var thisTop = targetTrigger.offset().top, thisLeft = $this.offset().left; // 鎸夐挳浣嶇疆 var thisW = targetTrigger.outerWidth(true), thisH = $this.outerHeight(true); // 鎸夐挳灏哄 var tooltipW = targetTooltip.outerWidth(true), tooltipH = targetTooltip.outerHeight(true); // 姘旀场灏哄 // 鍥犱负 FF 鍜 IE 涓紝border 鍥涗釜杈圭殑鍊兼槸鍒嗗紑鍐欑殑 // 鎵€浠ヤ负浜嗗吋瀹 FF 鍜 IE锛屽繀椤昏幏鍙栨煇涓€鍏蜂綋杈圭殑杈瑰 // 杩欓噷鍥涗釜杈圭殑杈瑰鏄竴鏍风殑锛屾墍浠ラ殢鎰忚幏鍙栦竴涓柟鍚戠殑鍗冲彲 var arrow = parseInt($tooltip.find('.tooltip-arr').css('border-right-width')); // 鍏煎FF鍜孖E鐨勫啓娉 if(oriation === 'top'){ targetTooltip.addClass(top).css({ 'top': thisTop - tooltipH - arrow*2, 'left': thisLeft - (tooltipW - thisW)/2, }); }else if(oriation === 'right') { targetTooltip.addClass(right).css({ 'top': thisTop - (tooltipH - thisH)/2, 'left': thisLeft + thisW + arrow*2, }); }else if(oriation === 'bottom') { targetTooltip.addClass(bottom).css({ 'top': thisTop + thisH + arrow*2, 'left': thisLeft - (tooltipW - thisW)/2, }); }else if(oriation === 'left') { targetTooltip.addClass(left).css({ 'top': thisTop - (tooltipH - thisH)/2, 'left': thisLeft - tooltipW - arrow*2, }); } } // 绉婚櫎 function remove(){ $tooltip.removeClass(top, right, bottom, left, specialClass, multiClass).css({'top': 'auto', 'left': 'auto'}).remove(); } $this.on({ 'mouseover': function(){ $('body').append($tooltip); if(multi !== '') { // 绠€鍗曞唴瀹 var thisContent = $this.attr('name'); // 瀵瑰簲鏂囧瓧 if(specialClass !== 'undefined'){ $tooltip.addClass(specialClass); // 濡傛湁鐗规畩鏍峰紡锛屾彁鍓嶅姞鍏 } }else{ // 澶嶆潅鍐呭 var thisContent = $('#' + $this.data('content')).html(); // 瀵瑰簲鐨勭粨鏋勫唴瀹癸紙闈炰粎鏂囧瓧锛 $tooltip.addClass(multiClass); } $tooltip.find('div').html(thisContent); locate($this, $tooltip); }, 'mouseleave': function(){ if(interact !== '') { // 涓嶈兘浜や簰锛屽嵆鍒掑嚭娑堝け remove(); }else{ // 鑳戒氦浜掞紝鍗冲垝鍑轰笉娑堝け锛岄渶鐐?鍏抽棴'鎸夐挳鎵嶈兘娑堝け $tooltip.find('[data-shut]').click(function(){remove();}); } } }); }); } tooltip(); // * 閫夐」鍗 // 1. 涓€涓?id'锛氱洰鏍囬€夐」鍗℃爣绛剧粍瀹瑰櫒缁欎釜id // 2. 涓や釜'data-role'锛氱洰鏍囬€夐」鍗℃爣绛剧粍'tablist'锛岀洰鏍囬€夐」鍗″唴瀹圭粍'id + tabbody' // 3. 鐩爣閫夐」鍗℃爣绛剧粍閫夐」鏍峰紡鍚嶅繀椤诲寘鍚?tabs-link' // 4. 鐩爣閫夐」鍗″唴瀹圭粍閫夐」鏍峰紡鍚嶅繀椤诲寘鍚?tabs-con' // 2. 鐩爣閫夐」鍗℃爣绛剧粍蹇呴』鏈?data-event'灞炴€э紝涓斿繀椤昏祴鍊硷紝涓€鑸粯璁ょ粰'click' // 4. 鍙湁id鍚嶇О鏄彲浠ラ殢鎰忓彇鐨勶紝鍏跺畠鐨勮淇濇寔涓嶅彉銆 // 5. 鏍囩缁勯€夐」瀹藉害鍧囧垎锛屽彧闇€缁欐爣绛剧粍鍔犱笂'data-equal="true"'鍗冲彲 // ----------------------------------------------------------------------- function tabs(){ $('[data-role="tablist"]').each(function(){ var $this = $(this), thisID = $this.attr('id'), thisEvent = $this.data('event'); var $thisTabLink = $this.find('.tabs-link'), $thisTabItem = $this.find('.tabs-item'); var $thisTabCon = $('[data-role="' + thisID + '-tabbody"]').children('.tabs-con'); var $thisTabMore = $('[data-role="' + thisID + '-tabMore"]').children('.tabs-con'); $thisTabLink.each(function(index){ $(this).on(thisEvent, function(){ var thisIndex = index; $thisTabLink.removeClass('active'); $(this).addClass('active'); $thisTabCon.removeClass('active'); $thisTabCon.eq(thisIndex).addClass('active'); $thisTabMore.removeClass('active'); $thisTabMore.eq(thisIndex).addClass('active'); }); }); // 鍒ゆ柇鏈夐棿璺濆拰鏃犻棿璺濅袱绉嶆儏鍐碉紝鍒嗗埆璁$畻绛夊垎鍊 // 涓哄吋瀹笽E10杩欎釜鏂规硶闇€鍐欏湪 'function equal()' 澶栭潰 var liNum = $thisTabItem.length; function wcalc(gap, i){ if(gap === 0) { $thisTabItem.css('width', (100/liNum) + '%'); }else{ var w1 = ($this.width() - gap*i*(liNum - 1))/liNum; $thisTabItem.css('width', w1); } } // 閫夐」鍗℃í鎺掔瓑鍒 function equal(){ var thisEqual = $this.attr('data-equal'); if(thisEqual === 'true') { // 鍒ゆ柇鏄惁IE8锛屽垎鍒祴鍊 if($('body').hasClass('ie8')) { // parseInt(value, radix)銆俽adix瑕佺粰鍊硷紙=10锛夛紝浠ヨВ鍐矷E8涓嬭幏鍙栦笉鍒板€肩殑闂 // margin 鍊奸渶鑾峰彇绗簩涓猯i鍏冪礌鐨勫乏杈硅窛锛屽洜涓篒E8涓负璁╀簡鏈€鍚庝竴涓猯i鍙宠竟璺濅负0锛屾晠灏嗚竟璺濆€肩粰鍒板乏渚т簡 var liMargin1 = parseInt(($thisTabItem.eq(1).css('margin-left')), 10); wcalc(liMargin1, 1); }else{ // margin 鍊奸渶鑾峰彇绗竴涓猯i鍏冪礌鐨勫彸杈硅窛锛屽洜涓虹涓€涓殑宸﹁竟璺濇牱寮忎腑寮哄埗涓?浜 var liMargin2 = parseInt($thisTabItem.eq(0).css('margin-right')); wcalc(liMargin2, 2); } // 濡傛灉鏄粍閫夐」鍗★紙group tabs锛夛紝闇€璁╂爣绛剧粍鏈変釜瀹藉害锛岃繖閲岄粯璁や负100% if($this.hasClass('group-tabs')) { $this.css('width', '100%'); } } }equal(); $(window).resize(function(){equal()}); }); } tabs(); // 寮圭獥 // ----------------------------------------------------------------------- // 搴旂敤鏂规硶锛 // 1. 涓€涓?id'锛氱洰鏍囧脊鍑虹獥鍙g埗绾ц挋鏉垮鍣ㄧ粰涓猧d // 2. 涓€涓?data-trigger'锛氳Е鍙戠洰鏍囩獥鍙g殑鎸夐挳锛屽繀椤讳笌绐楀彛id鍚屽悕 // 3. 涓や釜'data-role'锛氱洰鏍囧脊绐楃埗绾ц挋鏉?popup-container'锛岀洰鏍囧脊绐?popup' // 4. 1銆?涓殑鍚嶅瓧鍙互闅忔剰鍙栵紝涓や釜鍚嶅瓧鐩稿悓銆?涓殑鍚嶅瓧鍥哄畾涓嶅彲鍙樸€ function popup() { var $popupContainer = $('[data-role="popup-container"]'); $popupContainer.each(function(){ // 閬嶅巻寮圭獥鐖惰挋鏉 var $this = $(this); var thisID = $this.attr('id'); // 钂欐澘id var $thisTrigger = $('[data-trigger="' + thisID + '"]'); // 瀵瑰簲鐨勮Е鍙戞寜閽 var $thisPopup = $this.find('[data-role="popup"]'); // 瀵瑰簲鐨勭洰鏍囧脊绐 var $thisShut = $thisPopup.find('[data-role="popup-shut"]'); // 鍏抽棴鎸夐挳 function popupShut(target){ // 寮圭獥鍏抽棴鍛戒护 var $targetPopup = $(target).find('[data-role="popup"]'); $(target).fadeOut(); $targetPopup.fadeOut(); // 鍥犱负fadeIn/fadeOut鏄紦鍔ㄦ晥鏋滐紝闇€瑕佸姞涓€涓鏃跺櫒锛岃鏍峰紡褰掗浂鍔ㄤ綔寤跺悗涓€鐐圭偣 setTimeout(function(){ $targetPopup.css({ // 鍏抽棴鏃跺脊绐楀眳涓牱寮忛渶褰掗浂锛岄噸瑕侊紒锛 'top': 'auto', 'left': 'auto', 'margin-top': 0, 'margin-left': 0 }); }, 400); // 鎭㈠椤甸潰婊氬姩鏉 var pageHeight = $(window).height(), clientHeight = $(document).height(); if(clientHeight > pageHeight) { $('body').css('overflow-y', 'auto'); } } $thisTrigger.click(function(){ if($popupContainer.is(':visible')) { // 濡傛灉瑙﹀彂鎸夐挳鍦ㄥ脊绐楅噷锛岀偣鍑绘椂鍏堝叧闂寮圭獥 popupShut('[data-role="popup-container"]:visible'); } $this.fadeIn(); // 鏄剧ず钂欐澘 $thisPopup.fadeIn(); // 鏄剧ず寮圭獥 var thisWidth = $thisPopup.outerWidth(true); var thisHeight = $thisPopup.outerHeight(true); $thisPopup.css({ // 浣垮脊绐楀瀭鐩存按骞冲眳涓 'top': '50%', 'left': '50%', 'margin-top': -thisHeight/2, 'margin-left': -thisWidth/2 }); if($thisShut.length > 0){ $thisShut.click(function(){ // 鐐瑰叧闂寜閽椂 popupShut($this); // 璋冪敤寮圭獥鍏抽棴鍛戒护 }); } // 闅愯棌椤甸潰婊氬姩鏉 var pageHeight = $(window).height(), clientHeight = $(document).height(); if(clientHeight > pageHeight) { $('body').css('overflow-y', 'hidden'); } }); $this.click(function(){ // 鐐瑰脊绐楄挋鏉挎椂 popupShut($this); // 璋冪敤寮圭獥鍏抽棴鍛戒护 }); $thisPopup.click(function(e){ // 濡傛灉鐐瑰嚮鐨勬槸寮圭獥鍐呴儴锛岄槻姝㈠啋娉★紝閲嶈锛侊紒 e.stopPropagation(); }); }); } popup(); // 缁熶竴闃插啋娉★紙蹇呴』鏀惧湪JS搴曢儴锛 // ----------------------------------------------------------------------- function stopPropagation(){ $('body').on('click','[data-stopPropagation]',function (e) { e.stopPropagation(); }); } stopPropagation(); });