You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.5 KiB
88 lines
2.5 KiB
import "./common.js";
|
|
//#region js/investment.js
|
|
function setActiveNav() {
|
|
const pageNav = document.querySelector("[data-nav]")?.getAttribute("data-nav");
|
|
if (!pageNav) return;
|
|
document.querySelectorAll(".site-header__nav a").forEach((link) => {
|
|
const active = link.textContent.trim().startsWith(pageNav);
|
|
link.classList.toggle("is-active", active);
|
|
});
|
|
}
|
|
function initAnnounceSwiper() {
|
|
const root = document.querySelector(".iv-announce");
|
|
const el = root?.querySelector(".iv-announce__swiper");
|
|
if (!root || !el || !window.Swiper) return;
|
|
new window.Swiper(el, {
|
|
slidesPerView: 4,
|
|
spaceBetween: 40,
|
|
speed: 600,
|
|
navigation: {
|
|
prevEl: root.querySelector(".iv-announce__head .s-arrows__prev"),
|
|
nextEl: root.querySelector(".iv-announce__head .s-arrows__next")
|
|
},
|
|
breakpoints: {
|
|
0: {
|
|
slidesPerView: 1.15,
|
|
spaceBetween: 16,
|
|
navigation: {
|
|
prevEl: root.querySelector(".iv-announce__arrows-mobile .s-arrows__prev"),
|
|
nextEl: root.querySelector(".iv-announce__arrows-mobile .s-arrows__next")
|
|
}
|
|
},
|
|
768: {
|
|
slidesPerView: 2,
|
|
spaceBetween: 24
|
|
},
|
|
1200: {
|
|
slidesPerView: 4,
|
|
spaceBetween: 40
|
|
}
|
|
}
|
|
});
|
|
}
|
|
function initLearnItemClick() {
|
|
$(".iv-learn__item").on("click", function(event) {
|
|
if ($(event.target).closest("a").length) return;
|
|
const href = $(this).find("a[href]").attr("href");
|
|
if (href) window.location.href = href;
|
|
});
|
|
}
|
|
function initLearnToggle() {
|
|
const list = document.querySelector(".iv-learn__list");
|
|
const btn = document.querySelector(".iv-learn__more");
|
|
if (!list || !btn) return;
|
|
const items = list.querySelectorAll(".iv-learn__item");
|
|
if (items.length <= 6) {
|
|
btn.style.display = "none";
|
|
return;
|
|
}
|
|
btn.addEventListener("click", () => {
|
|
const isExpanded = list.classList.toggle("is-expanded");
|
|
btn.classList.toggle("is-expanded");
|
|
|
|
// 阻止平滑滚动库接管滚动
|
|
if (isExpanded) {
|
|
list.setAttribute("data-lenis-prevent", "");
|
|
} else {
|
|
list.removeAttribute("data-lenis-prevent");
|
|
}
|
|
});
|
|
|
|
// 阻止滚动事件冒泡(作为回退方案)
|
|
list.addEventListener("wheel", (e) => {
|
|
if (!list.classList.contains("is-expanded")) return;
|
|
const { scrollTop, scrollHeight, clientHeight } = list;
|
|
const atTop = e.deltaY < 0 && scrollTop <= 0;
|
|
const atBottom = e.deltaY > 0 && scrollTop + clientHeight >= scrollHeight - 1;
|
|
if (!atTop && !atBottom) {
|
|
e.stopPropagation();
|
|
}
|
|
}, { passive: false });
|
|
}
|
|
$(function() {
|
|
setActiveNav();
|
|
initAnnounceSwiper();
|
|
initLearnItemClick();
|
|
initLearnToggle();
|
|
});
|
|
//#endregion
|