let isMobileMenuOpened = false; $(document).ready(function () { // 檢查 Cookie,如果已存在則隱藏 infopop if (getCookie('allowCookie')) { $('#infopop').hide(); } $(window).resize(function () { const x = $(window).width(); if (x < 899) { $(".hamburger").show(); } if (x > 900) { $(".hamburger").hide(); } // ✅ 只在有展開手機選單過時才強制收起高度 if (x > 1000 && isMobileMenuOpened) { $("#header").animate({ "height": "74px" }, 300); isMobileMenuOpened = false; } }); $(window).trigger("resize"); $(".okbtn,.close2").click(function (e) { $('#infopop').slideUp(300); if (typeof agreeCookie === 'function') agreeCookie(); setCookie('allowCookie', '1', 365 * 10); if (typeof sendEvent === 'function') sendEvent('Click', 'footerCookie', '同意'); if (typeof sendBWQEvent === 'function') sendBWQEvent('contact_cookie'); }); function getCookie(name) { const nameEQ = name + "="; const ca = document.cookie.split(';'); for(let i=0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function setCookie(name,value,days) { document.cookie = name + "=" + (value || "") ; } $(".hamburger").click(function () { if (!isMobileMenuOpened) { openMobileMenu(); } else { closeMobileMenu(); } }); }); // 計算並設置合適的header高度 function calculateAndSetHeaderHeight() { // 先將header設為auto以獲取真實高度 $("#header").css("height", "auto"); // 計算選單內容的實際高度 const menuHeight = $(".menu__list").outerHeight(true); // 獲取header的實際高度 const headerAutoHeight = $("#header").outerHeight(); // 設定最小高度,確保選單有足夠的空間,並減去可能的額外像素 const minHeight = Math.max(headerAutoHeight, menuHeight + 74); // 將高度設回原始值,然後再動畫到新高度 $("#header").css("height", isMobileMenuOpened ? $("#header").height() + "px" : "74px"); $("#header").animate({ "height": minHeight + "px" }, 500, 'easeOutBack'); } // 打開行動裝置選單 function openMobileMenu() { calculateAndSetHeaderHeight(); isMobileMenuOpened = true; } // 關閉行動裝置選單 function closeMobileMenu() { $("#header").animate({ "height": "74px" }, 500, 'easeOutBack'); isMobileMenuOpened = false; } // 監聽子選單的開合 $(document).ready(function() { // 子選單點擊事件 $(document).on("click", ".dropdown.mobile-toggle > a", function(e) { if (window.innerWidth <= 1000 && isMobileMenuOpened) { // 給系統一點時間來顯示/隱藏子選單 setTimeout(function() { calculateAndSetHeaderHeight(); }, 50); } }); }); if (document.location.search.match(/type=embed/gi)) { window.parent.postMessage("resize", "*"); } $(document).ready(init); function init() { //$("#logo").stop().hide(); $(window).scroll(windowscroll); } // function windowscroll() { if ($(this).scrollTop() <= 0) { $(".pcbg").stop().animate({ top: '-74px' }, 100, 'easeOutBounce'); //$("#logo").stop().hide(); $('.menuhover').show(); } if ($(this).scrollTop() > 0) { $(".pcbg").stop().animate({ top: '0px' }, 100, 'easeOutBounce'); //$("#logo").stop().fadeIn(); $('.menuhover').hide(); } } function hambur() { $('.hamburger').click(); } $(function () { var $subMenus = $('.submenu > li') $('.menuqa > ul > li > a').click(function () { var $this = $(this), $ul = $this.next('ul') var $sibu = $('li.btncolor ul:visible') if ($sibu.length > 0) { $sibu.each(function (i, ele) { var $ele = $(ele), $parent = $ele.parent(), $a = $parent.find('>a') $a.removeClass('menu-open') .html($a.html().replace('_d.png', '_u.png')) .next('ul') .slideUp() }) } if ($ul.length > 0) { if ($ul.is(':visible')) { $this .removeClass('menu-open') .html($this.html().replace('_d.png', '_u.png')) .next() .slideUp() } else { $subMenus.slideDown() $this .removeClass('menu-open') .parent() .siblings('li') .find('>a img') .attr('src', function (i, v) { return this.src.replace('_d.png', '_u.png') }) .end() .find('ul') .slideUp() $this .addClass('menu-open') .html($this.html().replace('_u.png', '_d.png')) .next() .slideDown() } return false } }) $subMenus.find('a').click(function () { var $this = $(this), $ul = $this.next('ul') if ($ul.length > 0) { if ($ul.is(':visible')) { $this .removeClass('menu-open') .html($this.html().replace('_d.png', '_u.png')) .next() .slideUp() } else { $this .parent() .siblings('li') .find('>a img') .attr('src', function (i, v) { return this.src.replace('_d.png', '_u.png') }) .end() .find('ul') .slideUp() $this .addClass('menu-open') .html($this.html().replace('_u.png', '_d.png')) .next() .slideDown() } return false } }) $('a').focus(function () { $(this).blur() }) }) function txt01() { $('#pop01').slideDown(200); $('#downbtntxt01,#popbg').fadeIn(); $('#downbtntxt02,#downbtntxt03,#downbtntxt04').hide(); $("body").css({ "overflow-y": "hidden" }); } function txt02() { $('#pop01').slideDown(200); $('#downbtntxt02,#popbg').fadeIn(); $('#downbtntxt01,#downbtntxt03,#downbtntxt04').hide(); $("body").css({ "overflow-y": "hidden" }); } function txt03() { $('#pop01').slideDown(200); $('#downbtntxt03,#popbg').fadeIn(); $('#downbtntxt02,#downbtntxt01,#downbtntxt04').hide(); $("body").css({ "overflow-y": "hidden" }); } function txt04() { $('#pop01').slideDown(200); $('#downbtntxt04,#popbg').fadeIn(); $('#downbtntxt02,#downbtntxt03,#downbtntxt01').hide(); $("body").css({ "overflow-y": "hidden" }); } function closebtn() { $('#pop01,#pop02,#txt02,#txt03,#txt04,#popbg').slideUp(200); $("body").css('overflow-y', 'scroll'); } /*呼叫入站提醒*/ function txt11() { $('#pop02').slideDown(200); $('#txt01,#popbg').fadeIn(); $("body").css({ "overflow-y": "hidden" }); } function btn01() { $('#btn01 div,#bb01txt').stop().fadeIn(); $('#btn02 div,#btn03 div,#bb02txt,#bb03txt').hide(); } function btn02() { $('#btn02 div,#bb02txt').stop().fadeIn(); $('#btn01 div,#btn03 div,#bb01txt,#bb03txt').hide(); } function btn03() { $('#btn03 div,#bb03txt').stop().fadeIn(); $('#btn02 div,#btn01 div,#bb02txt,#bb01txt').hide(); } function myFunction() { alert("即將上線,敬請期待"); } /*主選單連結*/ //logo $('.logoPC,.logoMP').on('click', function () { location = '/zh/siteassets/canceraway/academy'; }) //首頁 $('.btn01').on('click', function () { location = 'index.html'; sendEvent('Click','Header','首頁');sendBWQEvent('contact_Home'); }) //得獎公布 $('.btn02').on('click', function () { myFunction(); //parent.location = '#'; sendEvent('Click','Header','得獎公布');sendBWQEvent('contact_Awarded'); }) //線上學院 $('.btn03').on('click', function () { parent.location = 'index.html#classin'; sendEvent('Click','Header','線上學院');sendBWQEvent('contact_OnlineAcademy'); }) //學習記錄 $('.btn04').on('click', function () { //myFunction(); //parent.location = 'Learning.html'; sendEvent('Click','Header','認識術後加速康復療程(ERAS)');sendBWQEvent('contact_Learning'); }) //註冊 $('.btn05').on('click', function () { myFunction(); //parent.location = 'StudentRegistration.html'; sendEvent('Click','Header','註冊');sendBWQEvent('contact_StudentRegistration'); }) //登入 $('.btn06').on('click', function () { myFunction(); //parent.location = 'Login.html'; sendEvent('Click','Header','登入');sendBWQEvent('contact_Login'); }) /*footer下方4連結*/ //活動注意事項 $('#downbtn01').on('click', function () { parent.location = 'javascript:txt01();'; sendEvent('Click','footer','活動注意事項');sendBWQEvent('contact_ActivityNotes'); }) //免責聲明 $('#downbtn02').on('click', function () { parent.location = 'javascript:txt02()'; sendEvent('Click','footer','免責聲明');sendBWQEvent('contact_Disclaimer') }) //個資法聲明 $('#downbtn03').on('click', function () { parent.location = 'javascript:txt03()'; sendEvent('Click','footer','個資法聲明');sendBWQEvent('contact_Personal') }) //Cookie政策及條款 $('#downbtn04').on('click', function () { parent.location = 'javascript:txt04()'; sendEvent('Click','footer','Cookie政策及條款');sendBWQEvent('contact_Cookie'); }) //Cookie政策及條款 $('#popbg').on('click', function () { closebtn(); }) /*線上學院類別連結*/ function class01() { location = '/zh/siteassets/canceraway/academy/page01'; } function class02() { location = '/zh/siteassets/canceraway/academy/page02'; } function class03() { location = '/zh/siteassets/canceraway/academy/page03'; } function class04() { location = '/zh/siteassets/canceraway/academy/page04'; } function class05() { location = '/zh/siteassets/canceraway/academy/page05'; } function class06() { location = '/zh/siteassets/canceraway/academy/page06'; } function class07() { location = '/zh/siteassets/canceraway/academy/page00'; } /**cookie同意***/ function agreeCookie(){ localStorage.setItem('cookie', '1'); }