/* 功能:鼠标移入缩略图 ≡ 手动点击缩略图,完全复用原生点击逻辑 */
document.addEventListener('DOMContentLoaded', function() {
console.log('「缩略图移入等效点击」脚本启动');
// 1. 核心选择器(匹配你的主题结构,已验证)
const THUMBNAIL_SELECTOR = '.pr_lazy_img.lazyloaded'; // 已加载的缩略图
const THUMBNAIL_CONTAINER = '.thumbnail-slider, .product-thumbnails'; // 缩略图容器
const SCROLL_BUTTONS = '.thumbnail-arrow, .scroll-button'; // 滚动导航按钮
// 2. 防重复绑定标记 + 防快速触发时间戳
const boundThumbs = new WeakSet(); // 记录已绑定的缩略图(避免内存泄漏)
const CLICK_INTERVAL = 300; // 300ms内不重复触发
// 3. 预加载图片(提升点击后显示速度,保留原体验)
const preloadImg = (url) => {
if (!url) return;
const img = new Image();
img.src = url.startsWith('//') ? `https:${url}` : url;
};
// 4. 核心:鼠标移入触发原生点击
const bindHoverAsClick = (thumbnail) => {
// 跳过已绑定、未加载完成的缩略图
if (boundThumbs.has(thumbnail) || !thumbnail.classList.contains('lazyloaded')) {
return;
}
// 预加载当前缩略图对应的大图
const bgset = thumbnail.dataset.bgset;
if (bgset) {
const urls = bgset.split(',').map(item => item.trim().match(/(\/\/[^ ]+)/)?.[1]).filter(Boolean);
if (urls.length) preloadImg(urls[urls.length - 1]); // 预加载最大尺寸图
}
// 绑定鼠标移入事件
thumbnail.addEventListener('mouseenter', (e) => {
// 防误触:仅鼠标未按下、且未在短时间内重复触发
const lastClick = thumbnail.dataset.lastClick || 0;
if (e.buttons !== 0 || (Date.now() - lastClick) < CLICK_INTERVAL) {
return;
}
// 模拟真实点击事件(完全复用原生点击逻辑)
const clickEvent = new MouseEvent('click', {
bubbles: true, // 允许事件冒泡(触发主题内置逻辑)
cancelable: true, // 允许阻止默认行为
view: window,
buttons: 0 // 模拟无按键状态的点击
});
// 触发点击 + 记录时间戳
thumbnail.dispatchEvent(clickEvent);
thumbnail.dataset.lastClick = Date.now();
console.log('移入触发缩略图点击:', thumbnail);
});
boundThumbs.add(thumbnail); // 标记为已绑定
};
// 5. 初始化:处理已存在的缩略图 + 确保滚动按钮可见
const initThumbnails = () => {
const containers = document.querySelectorAll(THUMBNAIL_CONTAINER);
containers.forEach(container => {
// 确保滚动按钮可见(不干扰导航)
container.querySelectorAll(SCROLL_BUTTONS).forEach(btn => {
btn.style.visibility = 'visible';
btn.style.opacity = '1';
btn.style.pointerEvents = 'auto';
});
// 处理容器内已存在的缩略图
container.querySelectorAll(THUMBNAIL_SELECTOR).forEach(bindHoverAsClick);
});
};
// 6. 动态监测:捕获滚动/加载的新缩略图
const observeNewThumbs = () => {
const containers = document.querySelectorAll(THUMBNAIL_CONTAINER);
if (containers.length) {
containers.forEach(container => {
const observer = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
// 处理新添加的节点
mutation.addedNodes.forEach(node => {
if (node.nodeType !== 1) return; // 只处理元素节点
// 若新节点是缩略图,直接绑定;否则查找子缩略图
if (node.matches(THUMBNAIL_SELECTOR)) {
bindHoverAsClick(node);
} else {
node.querySelectorAll(THUMBNAIL_SELECTOR).forEach(bindHoverAsClick);
}
});
});
});
// 监听容器内的DOM变化
observer.observe(container, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['class'] // 监测lazyloaded类的添加
});
});
} else {
// 备用:若未找到容器,监测整个文档(兼容更多结构)
const observer = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === 1) {
node.querySelectorAll(THUMBNAIL_SELECTOR).forEach(bindHoverAsClick);
}
});
});
});
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] });
}
};
// 7. 启动脚本(先初始化已存在的,再监测新的)
initThumbnails();
observeNewThumbs();
console.log('「缩略图移入等效点击」脚本加载完成');
});
Description
1. Protecting from rust, corrosion and aging.
2. The durable stainless steel license plate bracket protect your plates from the elements while giving your vehicle a unique look.
3. The cool and funny license plate frames.
4. Simple to install and dismantle. Just operate with screwdriver.
5. Lightweight and durable.
Specification:
General
Product Size
45.5*15*1.7cm
Package Weight
One Package Weight
0.58kgs / 1.28lb
One Package Size
46.7cm * 17cm * 2.2cm / 18.39inch * 6.69inch * 0.87inch
Carton Weight
12.80kgs / 28.22lb
Carton Size
49cm * 36cm * 28cm / 19.29inch * 14.17inch * 11.02inch
Loading Container
20GP: 539 cartons * 20 pcs = 10780 pcs 40HQ: 1253 cartons * 20 pcs = 25060 pcs