Skip to content

Commit 846d5ce

Browse files
authored
召唤佛祖的力量佑我成功
Signed-off-by: 本新同学 <yuanbenxin@outlook.com>
1 parent b135286 commit 846d5ce

File tree

1 file changed

+27
-77
lines changed

1 file changed

+27
-77
lines changed

docs/.vitepress/theme/components/Donate.vue

Lines changed: 27 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -22,90 +22,40 @@
2222
import { onMounted } from 'vue'
2323
2424
onMounted(() => {
25-
// 1. 强制禁用 medium-zoom
26-
try {
27-
// 移除 data-zoom 属性
28-
document.querySelectorAll('img[data-zoom]').forEach(img => {
29-
img.removeAttribute('data-zoom')
30-
})
31-
// 移除 medium-zoom 加的事件监听
32-
const imgs = document.querySelectorAll('img')
33-
imgs.forEach(img => {
34-
const clone = img.cloneNode(true)
35-
img.replaceWith(clone) // 用克隆替换原图,相当于移除了所有事件
36-
})
37-
console.log('✅ medium-zoom 已强制禁用')
38-
} catch (err) {
39-
console.warn('❌ 禁用 medium-zoom 失败', err)
40-
}
41-
42-
43-
// ===== 2. 自定义放大逻辑 =====
44-
<script setup>
45-
// 等待 DOM 渲染完成
46-
import { onMounted } from 'vue'
47-
48-
onMounted(() => {
49-
// 1. 强制禁用 medium-zoom
50-
try {
51-
// 移除它加的 data-zoom 属性
52-
document.querySelectorAll('img[data-zoom]').forEach(img => {
53-
img.removeAttribute('data-zoom')
54-
})
55-
// 移除 medium-zoom 加的事件监听
56-
const imgs = document.querySelectorAll('img')
57-
imgs.forEach(img => {
58-
const clone = img.cloneNode(true)
59-
img.replaceWith(clone) // 用克隆替换原图,相当于移除了所有事件
60-
})
61-
console.log('✅ medium-zoom 已强制禁用')
62-
} catch (err) {
63-
console.warn('❌ 禁用 medium-zoom 失败', err)
64-
}
25+
// ===== 1. 在 DOM 加载后把所有图片的点击事件解绑 =====
26+
document.querySelectorAll('img').forEach(img => {
27+
const clone = img.cloneNode(true)
28+
img.replaceWith(clone)
29+
})
6530
66-
// 2. 自定义放大逻辑(让两张图放大时大小一致)
67-
const imgs = document.querySelectorAll('.zoomable')
31+
// ===== 2. 自定义二维码点击放大 =====
32+
const imgs = document.querySelectorAll('.qrcode-wrapper img.zoomable')
6833
imgs.forEach(img => {
34+
img.style.cursor = 'zoom-in'
6935
img.addEventListener('click', () => {
7036
const overlay = document.createElement('div')
71-
overlay.style.position = 'fixed'
72-
overlay.style.top = 0
73-
overlay.style.left = 0
74-
overlay.style.width = '100vw'
75-
overlay.style.height = '100vh'
76-
overlay.style.background = 'rgba(0,0,0,0.8)'
77-
overlay.style.display = 'flex'
78-
overlay.style.alignItems = 'center'
79-
overlay.style.justifyContent = 'center'
80-
overlay.style.zIndex = 9999
81-
82-
const bigImg = document.createElement('img')
83-
bigImg.src = img.src
84-
bigImg.style.maxWidth = '80vw'
85-
bigImg.style.maxHeight = '80vh'
86-
bigImg.style.objectFit = 'contain'
87-
88-
// ✅ 统一大小逻辑
89-
// 先获取两张原图的尺寸,取一个最大宽高作为展示基准
90-
const allImgs = Array.from(document.querySelectorAll('.zoomable'))
91-
let maxW = 0, maxH = 0
92-
allImgs.forEach(i => {
93-
const temp = new Image()
94-
temp.src = i.src
95-
temp.onload = () => {
96-
maxW = Math.max(maxW, temp.width)
97-
maxH = Math.max(maxH, temp.height)
98-
}
99-
})
100-
// 给放大图固定成同一比例的尺寸(缩放到相同的宽高范围)
101-
bigImg.style.width = maxW + 'px'
102-
bigImg.style.height = maxH + 'px'
37+
overlay.className = 'modal-overlay'
10338
104-
overlay.appendChild(bigImg)
39+
const modal = document.createElement('div')
40+
modal.className = 'modal-card'
41+
42+
// ==== 统一放大尺寸,保证两张图视觉一致 ====
43+
const fixedWidth = 320
44+
const fixedHeight = 320
45+
46+
modal.innerHTML = `
47+
<img src="${img.src}" style="width: ${fixedWidth}px; height: ${fixedHeight}px; object-fit: contain;">
48+
<div class="modal-title">SecRandom团队再次感谢您的支持</div>
49+
<div class="modal-subtitle">点击周围空白关闭</div>
50+
`
51+
52+
overlay.appendChild(modal)
10553
document.body.appendChild(overlay)
10654
107-
overlay.addEventListener('click', () => {
108-
overlay.remove()
55+
overlay.addEventListener('click', (e) => {
56+
if (e.target === overlay) {
57+
document.body.removeChild(overlay)
58+
}
10959
})
11060
})
11161
})

0 commit comments

Comments
 (0)