@@ -617,117 +617,33 @@ export function initFlipCard() {
617617
618618 if ( ! flipCard || ! helpBtn || ! backBtn ) return ;
619619
620- // 检测是否为触摸设备 / Detect touch device
621- // 更准确的触摸设备检测方法
622- const isTouchDevice = window . matchMedia ( '(hover: none) and (pointer: coarse)' ) . matches ;
620+ const flipCardInner = flipCard . querySelector ( '.flip-card-inner' ) ;
621+ if ( ! flipCardInner ) return ;
623622
624- // 当前旋转角度 / Current rotation angle
625- let currentRotation = 0 ;
626- // 执行翻转操作 / Execute flip operation
627- function performFlip ( ) {
628- currentRotation += 180 ;
629- const flipCardInner = flipCard . querySelector ( '.flip-card-inner' ) ;
630- if ( flipCardInner ) {
631- flipCardInner . style . transform = `rotateX(${ currentRotation } deg)` ;
632-
633- // 添加或移除flipped类来控制按钮可见性(Firefox兼容性修复)
634- if ( currentRotation % 360 === 180 || currentRotation % 360 === - 180 ) {
635- flipCardInner . classList . add ( 'flipped' ) ;
636- } else {
637- flipCardInner . classList . remove ( 'flipped' ) ;
638- }
639- }
640- }
623+ // 翻转状态
624+ let isFlipped = false ;
641625
642- if ( isTouchDevice ) {
643- // 移动端:点击切换 / Mobile: click to toggle
644- helpBtn . addEventListener ( 'click' , ( e ) => {
645- e . preventDefault ( ) ;
646- e . stopPropagation ( ) ;
647- performFlip ( ) ;
648- } ) ;
649-
650- backBtn . addEventListener ( 'click' , ( e ) => {
651- e . preventDefault ( ) ;
652- e . stopPropagation ( ) ;
653- performFlip ( ) ;
654- } ) ; } else {
655- // 桌面端:鼠标悬停持续旋转 / Desktop: hover to continuously rotate
656- let rotationInterval ;
657- let isHovering = false ;
658-
659- // 开始持续旋转
660- function startContinuousRotation ( ) {
661- if ( isHovering ) return ; // 已经在旋转中
662- isHovering = true ;
663-
664- // 立即执行一次旋转
665- performFlip ( ) ;
666-
667- // 然后每800ms旋转一次(与CSS动画时长一致)
668- rotationInterval = setInterval ( ( ) => {
669- if ( isHovering ) {
670- performFlip ( ) ;
671- }
672- } , 800 ) ;
673- }
674-
675- // 停止持续旋转
676- function stopContinuousRotation ( ) {
677- isHovering = false ;
678- if ( rotationInterval ) {
679- clearInterval ( rotationInterval ) ;
680- rotationInterval = null ;
681- }
682- }
683-
684- // 检查鼠标是否在任一按钮上
685- function isMouseOverButton ( e ) {
686- const helpBtnRect = helpBtn . getBoundingClientRect ( ) ;
687- const backBtnRect = backBtn . getBoundingClientRect ( ) ;
688- const x = e . clientX ;
689- const y = e . clientY ;
690-
691- // 检查是否在帮助按钮上
692- const onHelpBtn = x >= helpBtnRect . left && x <= helpBtnRect . right &&
693- y >= helpBtnRect . top && y <= helpBtnRect . bottom ;
694-
695- // 检查是否在返回按钮上
696- const onBackBtn = x >= backBtnRect . left && x <= backBtnRect . right &&
697- y >= backBtnRect . top && y <= backBtnRect . bottom ;
698-
699- return onHelpBtn || onBackBtn ;
626+ // 简单的翻转函数
627+ function toggleFlip ( ) {
628+ isFlipped = ! isFlipped ;
629+ if ( isFlipped ) {
630+ flipCardInner . classList . add ( 'flipped' ) ;
631+ } else {
632+ flipCardInner . classList . remove ( 'flipped' ) ;
700633 }
701-
702- // 监听整个卡片的鼠标移动
703- flipCard . addEventListener ( 'mousemove' , ( e ) => {
704- if ( isMouseOverButton ( e ) ) {
705- if ( ! isHovering ) {
706- startContinuousRotation ( ) ;
707- }
708- } else {
709- if ( isHovering ) {
710- stopContinuousRotation ( ) ;
711- }
712- }
713- } ) ;
714-
715- // 监听鼠标离开卡片
716- flipCard . addEventListener ( 'mouseleave' , ( ) => {
717- stopContinuousRotation ( ) ;
718- } ) ;
719-
720- // 按钮点击事件(保持原有功能)
721- helpBtn . addEventListener ( 'click' , ( e ) => {
722- e . preventDefault ( ) ;
723- e . stopPropagation ( ) ;
724- performFlip ( ) ;
725- } ) ;
726-
727- backBtn . addEventListener ( 'click' , ( e ) => {
728- e . preventDefault ( ) ;
729- e . stopPropagation ( ) ;
730- performFlip ( ) ;
731- } ) ;
732634 }
635+
636+ // 帮助按钮点击事件
637+ helpBtn . addEventListener ( 'click' , ( e ) => {
638+ e . preventDefault ( ) ;
639+ e . stopPropagation ( ) ;
640+ toggleFlip ( ) ;
641+ } ) ;
642+
643+ // 返回按钮点击事件
644+ backBtn . addEventListener ( 'click' , ( e ) => {
645+ e . preventDefault ( ) ;
646+ e . stopPropagation ( ) ;
647+ toggleFlip ( ) ;
648+ } ) ;
733649}
0 commit comments