@@ -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