Twotrees Store
.header-wrapper--border-bottom:hover .header__heading-logo,
sticky-header .header__heading-logo {
filter: invert(1);
transition: filter 0.3s ease;
}
@media(max-width: 989px) {
.header-wrapper--border-bottom:hover .header__heading-logo,
sticky-header .header__heading-logo {
max-width: 75px;
}
}
document.addEventListener('DOMContentLoaded', function () {
// 创建一个观察器实例
const observer = new MutationObserver(function(mutations) {
const motherBoxes = document.querySelectorAll('.sales-box');
if (motherBoxes.length > 0) {
motherBoxes.forEach(box => {
const newSvg = `<svg t="1783758030092" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4464" width="25" height="25"><path d="M320 768.042667c277.333333-128 256-554.688 256-554.688h42.666667s42.666667 469.354667-189.653334 635.392L320 768.042667z" fill="#795548" p-id="4465"></path><path d="M256 277.333333c-0.469333-38.613333 14.997333-77.333333 39.978667-107.754666 25.024-30.272 63.125333-53.824 105.365333-60.586667 42.218667-7.146667 84.842667 2.688 118.357333 21.610667 33.728 19.178667 60.608 46.08 77.632 80.384-37.824-5.546667-70.122667-13.333333-100.309333-17.258667-30.101333-4.16-56.853333-4.586667-81.813333-0.533333s-49.472 12.8-75.562667 27.029333C313.450667 234.368 286.784 255.253333 256 277.333333zM874.666667 277.333333l-74.432-37.76c-21.888-10.752-41.642667-18.794667-60.48-23.872-18.858667-5.12-37.546667-7.914667-60.586667-7.872C656.064 207.573333 629.888 211.2 597.333333 213.333333c11.285333-30.570667 33.557333-54.634667 63.296-69.994666 29.504-15.338667 67.754667-19.733333 101.738667-9.877334 34.218667 9.365333 62.549333 30.592 81.834667 55.744 19.050667 25.493333 31.424 55.210667 30.464 88.128z" fill="#388E3C" p-id="4466"></path><path d="M597.333333 213.333333c-40.042667 21.866667-69.632 41.109333-93.056 60.629334-23.381333 19.477333-39.381333 38.186667-55.125333 59.669333-15.594667 21.461333-30.805333 46.869333-47.317333 76.885333C384.917333 440.448 368.085333 474.282667 341.333333 512c-26.56-37.866667-37.482667-79.936-37.632-123.84 0.32-43.541333 12.885333-90.218667 42.048-129.984 28.458667-39.957333 74.56-69.568 121.749334-77.525333C514.517333 172.821333 562.325333 182.293333 597.333333 213.333333zM810.666667 533.333333c-24.789333-36.010667-41.749333-66.432-57.578667-94.933333a3325.909333 3325.909333 0 0 0-42.773333-76.928c-13.653333-23.253333-26.538667-44.608-43.776-67.797333C649.493333 270.058667 627.178667 245.952 597.333333 213.333333c39.402667-19.989333 84.736-19.242667 125.909334-2.837333 41.216 16.426667 76.437333 49.024 97.834666 86.848a228.714667 228.714667 0 0 1 30.208 120.64c-1.770667 40.554667-12.373333 80.938667-40.618666 115.349333z" fill="#4CAF50" p-id="4467"></path><path d="M917.333333 789.354667s-21.333333 42.666667-85.333333 42.666666-85.333333-42.666667-85.333333-42.666666-21.333333 42.666667-85.333334 42.666666-85.333333-42.666667-85.333333-42.666666-21.333333 42.666667-85.333333 42.666666-85.333333-42.666667-85.333334-42.666666-21.333333 42.666667-85.333333 42.666666-85.333333-42.666667-85.333333-42.666666-21.333333 42.666667-85.333334 42.666666v85.333334h768v-128z" fill="#2196F3" p-id="4468"></path><path d="M106.666667 917.333333l576 0.021334s-192-170.666667-576-192V917.333333z" fill="#FFC107" p-id="4469"></path><path d="M597.333333 213.333333c-85.333333 106.666667-106.666667 341.333333-106.666666 341.333334M597.333333 213.333333c2.453333 39.786667 3.370667 68.714667 1.536 97.856a418.133333 418.133333 0 0 1-13.568 82.858667 368.576 368.576 0 0 1-32.192 80.32C538.24 501.077333 520.234667 527.573333 490.666667 554.666667c-23.488-32.874667-32.448-66.005333-36.522667-98.538667a255.146667 255.146667 0 0 1 7.722667-95.936 244.266667 244.266667 0 0 1 44.650666-88.149333c21.76-26.218667 50.88-51.2 90.816-58.709334z" fill="#8BC34A" p-id="4470"></path></svg>`
const existingSvg = box.querySelector('svg');
if (existingSvg) {
const svgWrapper = document.createElement('div');
svgWrapper.className = 'svg-wrapper';
svgWrapper.innerHTML = newSvg;
existingSvg.parentNode.replaceChild(svgWrapper, existingSvg);
} else {
const svgWrapper = document.createElement('div');
svgWrapper.className = 'svg-wrapper';
svgWrapper.innerHTML = newSvg;
box.appendChild(svgWrapper);
}
});
observer.disconnect();
return true;
}
return false;
});
// 配置观察器选项
const config = {
childList: true, // 观察目标子节点的变化,添加或删除
subtree: true // 观察后代节点
};
// 开始观察整个 document
observer.observe(document.body, config);
// bundles-box SVG 插入(同上逻辑)
const observerBundles = new MutationObserver(function(mutations) {
const bundlesBoxes = document.querySelectorAll('.bundles-box');
if (bundlesBoxes.length > 0) {
bundlesBoxes.forEach(box => {
if (box.querySelector('.svg-wrapper')) return; // 已处理过则跳过
const newSvg = `<svg t="1772439140184" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9799" width="24" height="24"><path d="M450.133333 934.4c-8.533333 0-17.066667-2.133333-23.466666-4.266667-61.866667-17.066667-381.866667-85.333333-211.2-514.133333 0 0 29.866667 96 83.2 96 12.8-202.666667 217.6-243.2 128-465.066667 0 0 238.933333 55.466667 268.8 337.066667 0 0 34.133333-89.6 102.4-98.133333 0 0-21.333333 49.066667 0 123.733333 0 0 200.533333 364.8-160 514.133333 0 0-21.333333 8.533333-46.933334 12.8 166.4-168.533333-96-341.333333-96-341.333333 10.666667 89.6-211.2 194.133333-44.8 339.2z" fill="#d81e06" p-id="9800"></path></svg>`;
if (!newSvg) return;
const existingSvg = box.querySelector('svg');
if (existingSvg) {
const svgWrapper = document.createElement('div');
svgWrapper.className = 'svg-wrapper';
svgWrapper.innerHTML = newSvg;
existingSvg.parentNode.replaceChild(svgWrapper, existingSvg);
} else {
const svgWrapper = document.createElement('div');
svgWrapper.className = 'svg-wrapper';
svgWrapper.innerHTML = newSvg;
box.insertBefore(svgWrapper, box.firstChild); // 插入到前面
}
});
observerBundles.disconnect();
}
});
observerBundles.observe(document.body, config);
});
document.addEventListener('DOMContentLoaded', function () {
function updateLogoInvert() {
// 获取 header 内的图标元素,它应该是白色的
const iconElement = document.querySelector('.header .header__icon');
if (!iconElement) {
return;
}
// 获取计算后的实际颜色值
let computedColor = getComputedStyle(iconElement).color;
// 解析RGB值
const rgbMatch = computedColor.match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/);
if (!rgbMatch) {
return;
}
// 检查是否是白色或接近白色
const isLightColor =
Number(rgbMatch[1]) > 200 && Number(rgbMatch[2]) > 200 && Number(rgbMatch[3]) > 200;
// 获取所有 logo 元素
const logos = document.querySelectorAll('.header__heading-logo');
// 根据图标颜色设置 logo 的 invert
logos.forEach((logo) => {
if (isLightColor) {
// 如果图标是浅色/白色,logo保持原样(假设logo本身是白色)
logo.style.filter = 'none';
} else {
// 如果图标是深色,logo需要反转
logo.style.filter = 'invert(1)';
}
});
}
// 初始执行一次
updateLogoInvert();
// 监听可能的颜色变化事件(如滚动、悬停等)
document.addEventListener('scroll', updateLogoInvert);
// 对于 hover 效果
const headerWrapper = document.querySelector('.header');
if (headerWrapper) {
headerWrapper.addEventListener('mouseenter', () => {
updateLogoInvert();
});
headerWrapper.addEventListener('mouseleave', () => {
updateLogoInvert();
});
}
});