Skip to content

Commit a6d5ab9

Browse files
committed
可以一直转
1 parent 28f85a9 commit a6d5ab9

File tree

2 files changed

+53
-40
lines changed

2 files changed

+53
-40
lines changed

client/css/body.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ body {
2020
transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
2121
transform-style: preserve-3d;
2222
transform-origin: center center; /* 设置旋转中心为卡片中心 */
23-
}
24-
25-
.flip-card.flipped .flip-card-inner {
26-
transform: rotateX(180deg);
23+
transform: rotateX(0deg); /* 初始状态 */
2724
}
2825

2926
.flip-card-front,
@@ -32,6 +29,7 @@ body {
3229
top: 0;
3330
left: 0;
3431
width: 100%;
32+
height: 100%;
3533
backface-visibility: hidden;
3634
border-radius: 14px;
3735
padding: 39px 15px 20px 15px;

client/js/ui.js

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -591,66 +591,81 @@ export function initFlipCard() {
591591
const backBtn = document.getElementById('back-btn');
592592

593593
if (!flipCard || !helpBtn || !backBtn) return;
594-
// 检测是否为触摸设备 / Detect touch device
594+
595+
// 检测是否为触摸设备 / Detect touch device
595596
// 更准确的触摸设备检测方法
596597
const isTouchDevice = window.matchMedia('(hover: none) and (pointer: coarse)').matches;
597598

598-
// 翻转到帮助页面 / Flip to help page
599-
function flipToHelp() {
600-
flipCard.classList.add('flipped');
601-
}
599+
// 当前旋转角度 / Current rotation angle
600+
let currentRotation = 0;
602601

603-
// 翻转回登录页面 / Flip back to login page
604-
function flipToLogin() {
605-
flipCard.classList.remove('flipped');
602+
// 执行翻转操作 / Execute flip operation
603+
function performFlip() {
604+
currentRotation += 180;
605+
const flipCardInner = flipCard.querySelector('.flip-card-inner');
606+
if (flipCardInner) {
607+
flipCardInner.style.transform = `rotateX(${currentRotation}deg)`;
608+
}
606609
}
607610

608611
if (isTouchDevice) {
609612
// 移动端:点击切换 / Mobile: click to toggle
610613
helpBtn.addEventListener('click', (e) => {
611614
e.preventDefault();
612615
e.stopPropagation();
613-
flipToHelp();
616+
performFlip();
614617
});
615618

616619
backBtn.addEventListener('click', (e) => {
617620
e.preventDefault();
618621
e.stopPropagation();
619-
flipToLogin();
620-
});
621-
} else {
622-
// 桌面端:鼠标悬停切换 / Desktop: hover to toggle
623-
let hoverTimeout;
622+
performFlip();
623+
}); } else {
624+
// 桌面端:鼠标悬停持续旋转 / Desktop: hover to continuously rotate
625+
let rotationInterval;
626+
let isHovering = false;
624627

625-
helpBtn.addEventListener('mouseenter', () => {
626-
clearTimeout(hoverTimeout);
627-
hoverTimeout = setTimeout(() => {
628-
flipToHelp();
629-
}, 30); // 30ms延迟,避免误触
630-
});
631-
632-
helpBtn.addEventListener('mouseleave', () => {
633-
clearTimeout(hoverTimeout);
634-
});
628+
// 开始持续旋转
629+
function startContinuousRotation() {
630+
if (isHovering) return; // 避免重复启动
631+
isHovering = true;
632+
633+
// 立即执行一次旋转
634+
performFlip();
635+
636+
// 然后每800ms旋转一次(与CSS动画时长一致)
637+
rotationInterval = setInterval(() => {
638+
if (isHovering) {
639+
performFlip();
640+
}
641+
}, 800);
642+
}
635643

636-
// 鼠标离开卡片时返回登录页面
637-
flipCard.addEventListener('mouseleave', () => {
638-
clearTimeout(hoverTimeout);
639-
hoverTimeout = setTimeout(() => {
640-
flipToLogin();
641-
}, 30); // 30ms延迟,给用户时间查看内容
642-
});
644+
// 停止持续旋转
645+
function stopContinuousRotation() {
646+
isHovering = false;
647+
if (rotationInterval) {
648+
clearInterval(rotationInterval);
649+
rotationInterval = null;
650+
}
651+
}
643652

644-
// 鼠标进入卡片时取消返回
645-
flipCard.addEventListener('mouseenter', () => {
646-
clearTimeout(hoverTimeout);
653+
// 帮助按钮事件
654+
helpBtn.addEventListener('mouseenter', startContinuousRotation);
655+
helpBtn.addEventListener('mouseleave', stopContinuousRotation);
656+
helpBtn.addEventListener('click', (e) => {
657+
e.preventDefault();
658+
e.stopPropagation();
659+
performFlip();
647660
});
648661

649-
// 返回按钮点击事件(桌面端也可以点击)
662+
// 返回按钮事件(同样的逻辑)
663+
backBtn.addEventListener('mouseenter', startContinuousRotation);
664+
backBtn.addEventListener('mouseleave', stopContinuousRotation);
650665
backBtn.addEventListener('click', (e) => {
651666
e.preventDefault();
652667
e.stopPropagation();
653-
flipToLogin();
668+
performFlip();
654669
});
655670
}
656671
}

0 commit comments

Comments
 (0)