(function($) { // ========================================================== // 首頁紅眼廣告輪播 // ========================================================== $(window).on("load resize", function(){ let redEyePadding = document.body.clientWidth * 0.09 $(".redeye-carousel").trigger("destroy.owl.carousel") if($(".redeye-carousel .redeye-item").length>=1){ $(".redeye-carousel").owlCarousel({ loop : true, items : 1, nav : true, navText : ['',''], dots:false, responsive:{ 0:{ stagePadding: 25, margin: 10 }, 576:{ stagePadding: redEyePadding, margin: 15 } } }); } }) // ========================================================== // 相關連結梯形按鈕hover效果 // ========================================================== //二元一次方程式計算出斜線後 內為左外為右 //方程式求法為線上找兩點解方程 // y = ax + b a為斜率(各斷點共用) //別問斜率怎麼來的 算的 //斜率 const slope = -194/92 //紅藍的上方長度比例 const ration = 0.624324 $(window).on("load resize", function(){ let btnWidth = $(".relate-btn-group").width() let btnHeight = $(".relate-btn-group").height() //y = ax + b => b = y - ax //帶入中心點(理論上會在線上) let b = (btnHeight/2) - slope * (btnWidth/2) $(".relate-btn-group").on("mouseenter mousemove", function(e){ let eb = calcStairEventB(event) if(eb < b){ $(".relate-btn-group").removeClass("right-hover").addClass("left-hover") }else if(eb > b){ $(".relate-btn-group").removeClass("left-hover").addClass("right-hover") } //在中間因為多少有誤差所以維持原樣 }) $(".relate-btn-group").on("mouseleave", function(){ $(".relate-btn-group").removeClass("right-hover left-hover") }) $(".relate-btn-group").on("click", function(e){ let eb = calcStairEventB(event) if(eb < b){ window.open($(".relate-btn-group").data("left-link")) }else if(eb > b){ window.open($(".relate-btn-group").data("right-link")) } //在中間因為多少有誤差所以不動 }) }) function calcStairEventB(event){ let x = event.pageX - $(".relate-btn-group").offset().left let y = event.pageY - $(".relate-btn-group").offset().top let eb = (y - slope * x) return eb } // ========================================================== // 服務項目頁簽 // ========================================================== $(".allservice-tag").on("click", function(){ let index = $(this).data("index") let target = $(".allservice-news-group").eq(index) if(target){ $(".allservice-tag , .allservice-news-group").removeClass("show") $(this).addClass("show") target.addClass("show") } }) // ========================================================== // 影片錦集輪撥 // ========================================================== if($(".video-section .video-item").length>=1){ $(".video-carousel").owlCarousel({ nav : false, navText : ['',''], dots:true, dotsEach: false, responsive:{ 0:{ items: 1, margin: 0 }, 576:{ items: 3, margin: 18 }, 992:{ items: 3, margin: 30 } } }); } // ========================================================== // 影片錦集播放 // ========================================================== $(".video-play").on("click", function(){ let iframeSrc = $(this).data("iframe-src") if(iframeSrc){ //停止撥放中影片 pauseVideos() $(this).next(".video-box").find("iframe").prop("src", iframeSrc) $(this).addClass("hide") $(this).next(".video-box").removeClass("hide") } }) // ========================================================== // 影片錦集切換時停止其他撥放中影片 // ========================================================== $(".video-carousel").on("change.owl.carousel", function(){ pauseVideos() }) function pauseVideos(){ $(".video-iframe").each(function(){ $(this)[0].contentWindow.postMessage('{"event":"command","func":"'+'pauseVideo'+'","args":""'+'}','*') }) } // ========================================================== // 最新消息輪撥 // ========================================================== if($(".news-section .news-item").length>=1){ $(".news-carousel").owlCarousel({ nav : false, navText : ['',''], dots:true, dotsEach: false, responsive:{ 0:{ items: 1, margin: 0 }, 576:{ items: 3, margin: 18 }, 992:{ items: 3, margin: 30 } } }); } // ========================================================== // 最新消息切換顯示 // ========================================================== $(".news-cover").on("click", function(e){ if((document.body.clientWidth > 575) || ((document.body.clientWidth <= 575) && $(e.target).hasClass("news-plus"))){ //手機點選加號或桌機平板點選時顯示文章不要連結去文章頁 e.preventDefault() //讓文章高度變化 防止兩者不同高度 $(this).parent(".news-item").height($(this).height()) $(this).addClass("hide") $(this).next(".news-text").removeClass("hide").addClass("show") } }) $(window).on("resize", function(e){ $(".news-text").each(function(){ if($(this).hasClass("show")){ $(this).removeClass("show").addClass("hide") } }) $(".news-cover").removeClass("hide") $(".news-item").height("initial") }) // ========================================================== // 關係機構輪播 // ========================================================== if($(".friends-section .friends-item").length>=1){ $(".friends-carousel").owlCarousel({ nav : false, navText : ['',''], dots:true, dotsEach: false, responsive:{ 0:{ items: 2, margin: 11 }, 576:{ items: 4, margin: 12 }, 992:{ items: 5, margin: 18 } } }); } })($); // ========================================================== // 首頁計數器 // ========================================================== ;(function($) { // 累加計數器 function counterUp(target, amount, duration) { const animateStep = 20 const thisUnit = $(target).attr('data-unit') || '' const timeStep = amount / duration * animateStep let returnNumber = 0 let counterStep = 1 if(thisUnit && amount < 10) { counterStep = 100 } else if(thisUnit && amount < 20) { counterStep = 10 } function counter() { if(returnNumber < amount) { returnNumber = Math.ceil((returnNumber + timeStep) * counterStep) / counterStep setTimeout(counter, animateStep) } else { returnNumber = amount } $(target).text(addSeparator(returnNumber) + thisUnit) } counter() } // 數字加上千分位 function addSeparator(string) { const numString = string * 1 + '' const floatAry = numString.split('.') const numAry = floatAry[0].split('') const remainderNum = numAry.length % 3 let kiloNum = '' for(let i = numAry.length - 1; i >= 0; i--) { kiloNum = numAry[i] + kiloNum if((i - remainderNum) % 3 === 0 && i !== 0) { kiloNum = ',' + kiloNum } } if(floatAry[1]) { kiloNum = kiloNum + '.' + floatAry[1] } return kiloNum } $('.stat-data-container .stat-data-counter').each(function(i, ele) { const amountAry = $(ele).attr('data-amount').split(',') const thisAmount = parseFloat(amountAry.reduce((prev, ele) => prev + ele, '')) const counterTime = 1.5 * 1000 counterUp(ele, thisAmount, counterTime) }) })($)