198 lines
6.8 KiB
JavaScript
198 lines
6.8 KiB
JavaScript
var initFilter = 'all';
|
|
const DESIGN_WIDTH = 1920;
|
|
const BASE_REM = 32;
|
|
const MIN_FONT_SIZE = 12;
|
|
const MAX_FONT_SIZE = 48;
|
|
|
|
function debounce(fn, delay = 100) {
|
|
let timer = null;
|
|
return () => {
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => fn(), delay);
|
|
};
|
|
}
|
|
|
|
function restoreNavLinkPlain(wrap) {
|
|
var inner = wrap.querySelector('.nav-link-marquee-inner');
|
|
if (!inner) return;
|
|
var seg = wrap.querySelector('.nav-link-marquee-seg');
|
|
var txt = seg ? seg.textContent : '';
|
|
wrap.innerHTML = '';
|
|
var t = document.createElement('span');
|
|
t.className = 'nav-link-text';
|
|
t.textContent = txt;
|
|
wrap.appendChild(t);
|
|
}
|
|
|
|
function setupNavLinkMarqueeForLink(link) {
|
|
var wrap = link.querySelector('.nav-link-text-wrap');
|
|
if (!wrap) return;
|
|
restoreNavLinkPlain(wrap);
|
|
link.classList.remove('nav-link--marquee');
|
|
var textEl = wrap.querySelector('.nav-link-text');
|
|
if (!textEl) return;
|
|
if (textEl.scrollWidth <= wrap.clientWidth + 1) return;
|
|
var txt = textEl.textContent;
|
|
var inner = document.createElement('span');
|
|
inner.className = 'nav-link-marquee-inner';
|
|
var seg1 = document.createElement('span');
|
|
seg1.className = 'nav-link-marquee-seg';
|
|
seg1.textContent = txt;
|
|
var seg2 = document.createElement('span');
|
|
seg2.className = 'nav-link-marquee-seg';
|
|
seg2.setAttribute('aria-hidden', 'true');
|
|
seg2.textContent = txt;
|
|
inner.appendChild(seg1);
|
|
inner.appendChild(seg2);
|
|
wrap.innerHTML = '';
|
|
wrap.appendChild(inner);
|
|
link.classList.add('nav-link--marquee');
|
|
var half = inner.scrollWidth / 2;
|
|
var pxPerSec = 35;
|
|
inner.style.animationDuration = Math.max(6, half / pxPerSec) + 's';
|
|
}
|
|
|
|
function initNavLinkMarquee() {
|
|
var desktop = window.matchMedia('(min-width: 992px)').matches;
|
|
var selector = desktop
|
|
? '.yuedong_head .yuedong-head-menu .navbar-collapse .nav-item > .nav-link'
|
|
: '.yuedong_head .mobile-menu .nav-item > .nav-link';
|
|
document.querySelectorAll(selector).forEach(function (link) {
|
|
setupNavLinkMarqueeForLink(link);
|
|
});
|
|
}
|
|
|
|
function setRemUnit() {
|
|
let screenWidth = document.documentElement.clientWidth || window.innerWidth;
|
|
if (screenWidth > 1630) {
|
|
screenWidth = 1920
|
|
} else if (screenWidth > 1500) {
|
|
screenWidth = 1820
|
|
} else if (screenWidth > 1200) {
|
|
screenWidth = 1440
|
|
} else if (screenWidth > 992) {
|
|
screenWidth = 1200
|
|
} else {
|
|
screenWidth = 992
|
|
}
|
|
let fontSize = screenWidth / (DESIGN_WIDTH / BASE_REM);
|
|
fontSize = Math.max(MIN_FONT_SIZE, Math.min(MAX_FONT_SIZE, fontSize));
|
|
document.documentElement.style.fontSize = `${fontSize}px`;
|
|
}
|
|
|
|
setRemUnit();
|
|
|
|
window.addEventListener('resize', debounce(setRemUnit));
|
|
window.addEventListener('orientationchange', debounce(setRemUnit));
|
|
$(function () {
|
|
function performLocalSearch($form) {
|
|
var formData = $form.serialize();
|
|
var basePath = '/search/';
|
|
window.location.href = formData ? `${basePath}?${formData}` : basePath;
|
|
}
|
|
|
|
$('.input-wrap-box input[name*="mobile"]').attr('type', 'number').attr('name', 'mobile');
|
|
$('.input-wrap-box input[name*="phone"]').attr('type', 'number').attr('name', 'mobile');
|
|
$('.input-wrap-box input[name*="tel"]').attr('type', 'number').attr('name', 'mobile');
|
|
$('.input-wrap-box input[name*="Whatsapp"]').attr('type', 'number').attr('name', 'mobile');
|
|
var previousIcon = `
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="7" height="13" viewBox="0 0 7 13" fill="none">
|
|
<path d="M6.5 12.5L0.5 6.5L6.5 0.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
`;
|
|
|
|
var nextIcon = `
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="7" height="13" viewBox="0 0 7 13" fill="none">
|
|
<path d="M0.5 12.5L6.5 6.5L0.5 0.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
`;
|
|
|
|
if ($(".yuedong-counter").length) {
|
|
$(".yuedong-counter").counterUp({
|
|
delay: 20,
|
|
time: 3000,
|
|
});
|
|
}
|
|
if ($(window).width() < 992) {
|
|
// 使用事件委托,适配 SPA 动态加载的页面内容
|
|
$(document).on("click", ".navbar-collapse .hasSubNav", function (e) {
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
$(this).siblings('.dropdown-menu').toggleClass('d-block')
|
|
});
|
|
|
|
$(document).on("click", ".navbar-collapse .hasSubNav span", function (e) {
|
|
e.stopPropagation()
|
|
var href = $(this).parent('a').attr('href')
|
|
if (href && href !== '#' && href !== '') {
|
|
window.location.href = href
|
|
}
|
|
});
|
|
|
|
$(document).on("click", ".navbar-collapse .dropdown-submenu", function (e) {
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
$(this).children('.dropdown-menu').toggleClass('d-block')
|
|
});
|
|
$(document).on("click", ".navbar-collapse .dropdown-submenu span", function (e) {
|
|
e.stopPropagation()
|
|
var href = $(this).parent('a').attr('href')
|
|
if (href && href !== '#' && href !== '') {
|
|
window.location.href = href
|
|
}
|
|
});
|
|
}
|
|
|
|
// 搜索相关 — 使用事件委托适配 SPA
|
|
$(document).on('click', '.head-search em', function () {
|
|
$('.serchbox').addClass('active');
|
|
$('.serchbox .submit_text').trigger('focus');
|
|
});
|
|
$(document).on('click', '.serchbox', function () {
|
|
$('.serchbox').removeClass('active');
|
|
});
|
|
$(document).on('click', '.serchbox form', function (e) {
|
|
e.stopPropagation();
|
|
});
|
|
$(document).on('submit', '.serchbox form', function (e) {
|
|
e.preventDefault();
|
|
performLocalSearch($(this));
|
|
});
|
|
$(document).on('click', '.serchbox .submit_btn', function (e) {
|
|
e.preventDefault();
|
|
performLocalSearch($(this).closest('form'));
|
|
});
|
|
|
|
$(window).scroll(function () {
|
|
if ($(this).scrollTop() > 100) {
|
|
$(".yuedong-head-menu").addClass("fixed-top")
|
|
} else {
|
|
$(".yuedong-head-menu").removeClass("fixed-top");
|
|
}
|
|
if (
|
|
document.body.scrollTop > 150 ||
|
|
document.documentElement.scrollTop > 150
|
|
) {
|
|
$("#scroll-top").addClass("active");
|
|
} else {
|
|
$("#scroll-top").removeClass("active");
|
|
}
|
|
});
|
|
|
|
$(document).on("click", "#scroll-top", function () {
|
|
$("html, body").animate({ scrollTop: 0 }, 1000);
|
|
return false;
|
|
});
|
|
|
|
$(document).on("click", "#go-back", function () {
|
|
window.history.go(-1);
|
|
return false;
|
|
});
|
|
|
|
initNavLinkMarquee();
|
|
$(window).on('resize', debounce(initNavLinkMarquee));
|
|
$(window).on('load', function () {
|
|
initNavLinkMarquee();
|
|
});
|
|
});
|