$(document).ready(function() { /*------------------------- heroheader -------------------------*/ $(".hamburger").click(function(){ $(".navbox").addClass("show"); }); $(".close_hamburger").click(function(){ $(".navbox").removeClass("show"); }); $(".dropBt").on('click',function(e) { e.preventDefault(); $(this) .siblings(".haveDrop") .toggleClass("open"); $(this) .closest(".toggleIcon") .toggleClass("closebt"); $(this) .parent() .siblings() .find(".dropBt") .removeClass("active"); $(this) .parent() .siblings() .find(".haveDrop") .removeClass("open"); $(this) .parent() .siblings() .find(".toggleIcon") .removeClass("closebt"); }); $(".navbox").on('mouseleave', function() { // 移除之前添加的类 $(".haveDrop").removeClass("open"); $(".toggleIcon").removeClass("closebt"); $(".dropBt").removeClass("active"); }); $(".mod-language").click(function () { $(".language-content").toggle(200); }); $(".mod-language").on('mouseleave', function() { $(".language-content").hide(200); }); $(".mod-message").click(function () { $(".message-content").toggle(200); }); $(".mod-message").on('mouseleave', function() { $(".message-content").hide(200); }); $(".lineshare").click(function () { $(".lineshare-content").toggle(200); }); $(".lineshare").on('mouseleave', function() { $(".lineshare-content").hide(200); }); $(".membernav").click(function () { $(".lists").toggle(200); }); // $(".membernav").on('mouseleave', function() { // $(".lists").hide(200); // }); $(".moreopen").click(function () { $(this).find('.more-inner').toggle(200); }); $(".ic_more").click(function () { $(".sidenav").toggle(200); }); $('.ringopen').click(function() { $(this).closest('.items').find('.drop').toggle(200); $(this) .parent().parent() .siblings() .find(".drop") .hide(200); $(this).closest('.items').find('.ringopen').toggleClass('show'); $(this) .parent().parent() .siblings() .find(".ringopen") .removeClass('show'); }); $('.titleopen').click(function() { $(this).parent().find('.drop').toggle(200); $(this) .parent().parent() .siblings() .find(".drop") .hide(200); $(this) .parent().parent() .siblings() .find(".ringopen") .removeClass('show'); }); /*------------------------- 首頁大圖輪撥 -------------------------*/ var swiper = new Swiper(".Swiperkv", { loop: true, centeredSlides: true, slidesPerView: 1, spaceBetween: 0, preloadImages: true, // 預加載圖片 updateOnImagesReady: true, // 圖片加載完成後更新 autoplay: { delay: 8000, disableOnInteraction: false, }, pagination: { el: ".swiper-pagination", clickable: true, }, on: { init: function () { this.update(); // 確保初始化後更新 }, }, }); var swiper = new Swiper(".indexSwiper1", { slidesPerView: 1, spaceBetween: 12, navigation: { nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev", }, pagination: { el: ".swiper-pagination", }, breakpoints: { 768: { slidesPerView: 3, spaceBetween: 20, }, }, }); var swiper = new Swiper(".indexSwiper2", { effect: "cards", grabCursor: true, centeredSlides: true, loop: true, }); var swiper = new Swiper(".indexSwiper3", { slidesPerView: 3, spaceBetween: 12, navigation: { nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev", }, pagination: { el: ".swiper-pagination", }, breakpoints: { 768: { slidesPerView: 6, spaceBetween: 20, }, }, }); /*------------------------- 首頁-tab選單 -------------------------*/ function setupTabs(tabClass, showTabIndex) { $(tabClass).each(function() { var $tab = $(this); var $defaultLi = $("ul.tabs li", $tab).eq(showTabIndex).addClass("active"); $($defaultLi.find("a").attr("href")).siblings().hide(); $("ul.tabs li", $tab).click(function() { var $this = $(this), _clickTab = $this.find("a").attr("href"); $this.addClass("active").siblings(".active").removeClass("active"); $(_clickTab).stop(false, true).fadeIn().siblings().hide(); return false; }).find("a").focus(function() { this.blur(); }); }); } // 第一個區塊 setupTabs(".p_tab1", 0); // 第二個區塊 setupTabs(".p_tab2", 0); // 第三個區塊 setupTabs(".p_tab3", 0); /*------------------------- 會員頁sidemenu當前頁面位置 -------------------------*/ $(".userNav a").each(function() { if ($(this).attr("href") == window.location.pathname.split("/")[1]) $(this).addClass("active"); }); /*------------------------- 類別選單 -------------------------*/ var swiper = new Swiper(".categorySwiper", { slidesPerView: 4, spaceBetween: 12, navigation: { nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev", }, breakpoints: { 640: { slidesPerView: 5, spaceBetween: 0, }, 720: { slidesPerView: 12, spaceBetween: 0, }, }, }); var swiper = new Swiper(".categorySwiper2", { slidesPerView: 2, spaceBetween: 12, navigation: { nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev", }, breakpoints: { 680: { slidesPerView: 5, spaceBetween: 12, }, }, }); var swiper = new Swiper(".categorySwiper3", { slidesPerView: 2, spaceBetween: 1, navigation: { nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev", }, breakpoints: { 640: { slidesPerView: 5, spaceBetween: 1, }, }, }); /*------------------------- lightbox -------------------------*/ $(".lightbox-close").click(function () { $(".lightbox-target").removeClass('lightboxopen'); }); $(".newmargin").click(function () { $(".lightbox-margin").addClass('lightboxopen'); }); $(".esgfuture").click(function () { $(".lightbox-esgfuture").addClass('lightboxopen'); }); /*------------------------- FAQ -------------------------*/ $("li.a").hide(); $("li.q").click(function() { //gets next element //opens .a of selected question $(this) .next() .slideToggle(500) //selects all other answers and slides up any open answer .siblings("li.a") .slideUp(); //Grab img from clicked question var img = $(this).children("i"); //Remove Rotate class from all images except the active $("i") .not(img) .removeClass("rotate"); //toggle rotate class img.toggleClass("rotate"); }); /*------------------------- 右側欄位跟著滾動gsap -------------------------*/ gsap.registerPlugin(ScrollTrigger); ScrollTrigger.matchMedia({ // 当视口宽度大于等于 1000px 时执行 "(min-width: 820px)": function () { // 获取所有的 desktopContentSection 元素 // const sections = document.querySelectorAll(".desktopContentSection"); // 固定元素 gsap.to(".rightfix", { scrollTrigger: { trigger: ".rightfix", start: "bottom bottom", // 当底部进入视口底部时开始固定 endTrigger: ".leftfix", // 结束固定的元素 end: "bottom bottom", // 当底部进入视口底部时结束固定 pin: true, pinSpacing: false, // 不要为固定元素添加额外的填充 markers: false, }, }); }, "(min-width: 1140px)": function () { gsap.to(".sharepin", { scrollTrigger: { trigger: ".sharepin", start: "top-=120 top", // 当底部进入视口底部时开始固定 endTrigger: ".shareend", // 结束固定的元素 end: "top center", // 当底部进入视口底部时结束固定 pin: true, pinSpacing: false, // 不要为固定元素添加额外的填充 }, }); }, }); /*------------------------- 字級大小 -------------------------*/ var fontSizeIndex = 0; var maxFontSizeIndex = 3; $(".ic_fsize").on("click", function () { if (fontSizeIndex < maxFontSizeIndex) { fontSizeIndex++; $(".fsize").css("font-size", "+=1"); } else { // Reset font size to the original size or take another action as needed fontSizeIndex = 0; $(".fsize").css("font-size", "1em"); } }); /*------------------------- 文件ready ok jquery結束 -------------------------*/ });