// Mweb套版專用的js補丁 v10.0 // 作者: Alan 2016.08.24 var mobileMode = 1280; $(document).ready(function(){ // 以下常用 var WW = $(window).width(); var WH = $(window).height(); fixWebFunction(); fixBreadcrumb(); fixColSide(); fixLagH(); autoTopNavPadding({moveRight:false}); autoSidebarSwitch(); autoActiveListSort({minGap:10}); fadeInWebsite(); // 以下客製 $('.lagH a').each(function(){ $(this).html($(this).html().replace(/體中文|体中文|glish/,'')); $(this).width($(this).height()) }) }); $(window).load(function() { // 以下常用 var WW = $(window).width(); var WH = $(window).height(); // 以下客製 setSameHight('.section02 .block'); setSameHight('.display_editor_data .col-6'); if(WW <= mobileMode){ $('.section01 .block').autoGap({minGap:10}); $('.section02 .block').autoGap({minGap:10}); } }).resize(function() { // 以下常用 var WW = $(window).width(); var WH = $(window).height(); autoTopNavPadding({moveRight:false}); autoActiveListSort({minGap:10}); // 以下客製 if(WW <= mobileMode){ $('.section01 .block').autoGap({minGap:10}); $('.section02 .block').autoGap({minGap:10}); }else{ $('.section01 .block , .section02 .block').css({'margin-left':0,'margin-right':0}) } setSameHight('.display_editor_data .col-6'); }); function fadeInWebsite() { // 功能概述: 網站載完淡入 $("body").css({ "opacity": 1, "transition": "opacity 0.3s" }); } function setSameHight(targets) { // 功能概述: 統一高度,以最高者為標準 $(targets).css({ 'height': "auto"}); var i = 0; var eachH = []; $(targets).each(function() { if($(targets).css('box-sizing') == 'border-box'){ eachH[i] = $(this).outerHeight(); }else{ eachH[i] = $(this).height(); } i++; }); $(targets).css({ 'height': Math.max.apply(Math, eachH)}); } function setSquare(targets) { // 功能概述: 設為正方形,高度等於寬度 $(targets).height($(targets).width()); } function autoTopNavPadding(custom) { // 功能概述: 自動算主選單選項間距 $("#navMenu > li").children("a").css({ "padding-left": 0, "padding-right": 0 }); $("#navMenu").css('width', 'auto'); $("#navMenu").width($("#navMenu").actual('width')); var navContainerW = $("#navMenu").width(); var liTotalW = 0; var liQuantity = $("#navMenu > li").length; $("#navMenu > li").each(function() { $(this).children('a').css({ "padding-left": 0, "padding-right": 0 }) $(this).children('a').width($(this).children('a').actual('width')); liW = parseInt($(this).children('a').outerWidth(true)); liTotalW += liW }); var liPadding = Math.floor((navContainerW - liTotalW) / (liQuantity * 2) * 10) / 10; $("#navMenu > li").children("a,div").css({ "padding-left": liPadding, "padding-right": liPadding }); preset = {moveRight:false} $.extend(preset,custom); if (preset.moveRight) { // 主選單文字靠右對齊,僅適合無邊框無背景的主選單 $("#navMenu").css({ "margin-left": liPadding, "margin-right": -liPadding }) } } function autoSidebarSwitch() { // 功能概述: 自動算左半邊展開按鈕的高度 var eachLeftNavListH = []; var i = 0; $(".sideCate a.tree").each(function() { eachLeftNavListH[i] = $(this).next().height(); i++; leftNavListPtop = $(this).next().css('padding-top'); leftNavListPbtm = $(this).next().css('padding-bottom'); $(this).css({ 'padding-top': leftNavListPtop, 'padding-bottom': leftNavListPbtm }); }) leftNavListH = Math.min.apply(Math, eachLeftNavListH); $(".sideCate a.tree").height(leftNavListH); } function autoActiveListSort(custom) { // 首次進入觸發listSort()函數 listSort(custom); // 模式切換觸發listSort()函數 $(".sort , .psort").click(function() { listSort(custom); }) function listSort(minGap) { // 功能概述: 產品列表各項修正 // 修正電子型錄 fixCatalog(); // 刪除mweb多餘標籤 $('.proList .img span').remove() // 統一燈箱、放大鏡結構 $('.proList > *:first-child').addClass('img') // 清除上次listSort()執行結果的值 $(".proList").css({ 'margin-right': 0, 'margin-left': 0, 'height': 'auto', 'clear':'none' }); // 3.清除上次listSort()執行結果的值 $('.proList .txt').css({ 'width': 'auto', 'height': 'auto', 'margin-bottom':'0' }); if($('.productGrid').length){ // 九宮格時 $('.proList .txt').outerWidth($('.proList .img').outerWidth()).css('margin-bottom', '1em'); setSameHight('.proList .txt') $('.proList').autoGap(minGap) }else{ // 橫式格時 $('.proList .txt').outerWidth($('.proList').width() - $('.proList .img').outerWidth(true)).css('min-width', '135px');; } } } $.fn.extend({ autoGap: function(custom){ // 功能概述: 通用自動算間距,可設定最小間距 var target = $(this); target.css({ 'margin-left': 0, 'margin-right': 0 }) // 判斷是否把padding納入計算 if(target.css('box-sizing')=='border-box'){ var containerW = target.parent().outerWidth(); }else{ var containerW = target.parent().width(); } var targetW = target.outerWidth(); var rowN = Math.floor(containerW / targetW); var space ,gap; var preset = {minGap:10}; $.extend(preset,custom); function countGap(){ space = containerW - targetW * rowN; gap = Math.floor(space / rowN / 2 * 10) / 10; }; countGap(); if(gap < preset.minGap){ rowN = rowN - 1; countGap() } target.css({ 'margin-left': gap, 'margin-right': gap }); } }); function fixCatalog() { // 功能概述: 修正電子型錄iframe排版 $('.gocatalog .proList .img').next('h3').wrap('
'); $('.gocatalog .proList .img').height($('.gocatalog .proList iframe').attr('height')).css({ 'background' : 'none', }); $('.gocatalog .proList iframe').width($('.gocatalog .proList iframe').attr('width')).css({ 'border-bottom': 'none', 'box-shadow': 'none', 'margin': '0 auto', 'box-shadow': '3px 3px 10px rgba(0,0,0,0.3)' }); } function fixBreadcrumb(){ // 修正麵包屑結構不一 $('.breadcrumb').wrap('