264264 font-size : 12px ;
265265 box-shadow : 0 4px 12px rgba (16 , 185 , 129 , 0.3 );
266266 }
267- .gesture -area {
268- background : # f1f5f9 ;
267+ .hover -area {
268+ background : # 3b82f6 ;
269269 border-radius : 8px ;
270270 height : 100% ;
271271 display : flex;
272272 flex-direction : column;
273273 align-items : center;
274274 justify-content : center;
275- color : # 64748b ;
275+ color : # fff ;
276276 font-weight : 600 ;
277+ cursor : pointer;
278+ transition : background .2s ;
277279 touch-action : none;
278- cursor : grab;
279280 }
280- .gesture-area .direction {
281- font-size : 32px ;
281+ .hover-area : hover {
282+ background : # 2563eb ;
283+ }
284+ .hover-area .status {
285+ font-size : 24px ;
282286 margin-bottom : 10px ;
283287 }
284- .gesture -area .hint {
288+ .hover -area .hint {
285289 font-size : 12px ;
286- color : # 94a3b8 ;
290+ opacity : 0.9 ;
287291 }
288- .event-test-element {
289- width : 100px ;
290- height : 100px ;
291- background : # ec4899 ;
292+ .gesture-area {
293+ background : # f1f5f9 ;
292294 border-radius : 8px ;
295+ height : 100% ;
293296 display : flex;
297+ flex-direction : column;
294298 align-items : center;
295299 justify-content : center;
296- color : # fff ;
300+ color : # 64748b ;
297301 font-weight : 600 ;
298- font-size : 12px ;
299- box-shadow : 0 4px 12px rgba (236 , 72 , 153 , 0.3 );
300302 touch-action : none;
303+ cursor : grab;
304+ }
305+ .gesture-area .direction {
306+ font-size : 32px ;
307+ margin-bottom : 10px ;
301308 }
309+ .gesture-area .hint {
310+ font-size : 12px ;
311+ color : # 94a3b8 ;
312+ }
302313 </ style >
303314</ head >
304315< body >
@@ -415,6 +426,19 @@ <h2>scale - Zoom</h2>
415426 < div class ="log " id ="scale-log "> Scroll wheel to zoom, drag to pan</ div >
416427 </ div >
417428
429+ <!-- hover 演示 -->
430+ < div class ="demo-card ">
431+ < h2 > hover - Hover</ h2 >
432+ < div class ="demo-area ">
433+ < div class ="hover-area " id ="hover-area ">
434+ < div class ="status " id ="hover-status "> 👆 Hover</ div >
435+ < div > Hover or touch</ div >
436+ < div class ="hint "> Pointer enter/leave</ div >
437+ </ div >
438+ </ div >
439+ < div class ="log " id ="hover-log "> Move pointer over the area</ div >
440+ </ div >
441+
418442 <!-- gesture 演示 -->
419443 < div class ="demo-card ">
420444 < h2 > gesture - Swipe</ h2 >
@@ -427,17 +451,7 @@ <h2>gesture - Swipe</h2>
427451 </ div >
428452 < div class ="log " id ="gesture-log "> Swipe up/down/left/right</ div >
429453 </ div >
430-
431- <!-- event 测试 -->
432- < div class ="demo-card ">
433- < h2 > Event Testing</ h2 >
434- < div class ="demo-area " id ="event-area ">
435- < div class ="event-test-element " id ="event-element ">
436- Test Element
437- </ div >
438- </ div >
439- < div class ="log " id ="event-log "> Event log will appear here</ div >
440- </ div >
454+
441455 </ div >
442456 </ div >
443457
@@ -647,6 +661,31 @@ <h2>Event Testing</h2>
647661 scaleArea . addEventListener ( 'pointerdown' , handleScale ) ;
648662 scaleArea . addEventListener ( 'wheel' , handleScale ) ;
649663
664+ // --- hover 演示 ---
665+ const hoverArea = document . getElementById ( 'hover-area' ) ;
666+ const hoverStatus = document . getElementById ( 'hover-status' ) ;
667+ const hoverLog = document . getElementById ( 'hover-log' ) ;
668+
669+ function handleHover ( e ) {
670+ pointer . hover ( e , {
671+ 'enter' : function ( e ) {
672+ hoverStatus . textContent = '✅ Entered' ;
673+ hoverArea . style . background = '#10b981' ;
674+ hoverLog . textContent = 'Pointer entered at (' + Math . round ( e . clientX ) + ', ' + Math . round ( e . clientY ) + ')' ;
675+ } ,
676+ 'move' : function ( e ) {
677+ hoverLog . textContent = 'Moving at (' + Math . round ( e . clientX ) + ', ' + Math . round ( e . clientY ) + ')' ;
678+ } ,
679+ 'leave' : function ( e ) {
680+ hoverStatus . textContent = '👆 Hover' ;
681+ hoverArea . style . background = '#3b82f6' ;
682+ hoverLog . textContent = 'Pointer left' ;
683+ }
684+ } ) ;
685+ }
686+ hoverArea . addEventListener ( 'pointerdown' , handleHover ) ;
687+ hoverArea . addEventListener ( 'pointerenter' , handleHover ) ;
688+
650689 // --- gesture 演示 ---
651690 const gestureArea = document . getElementById ( 'gesture-area' ) ;
652691 const gestureDir = document . getElementById ( 'gesture-dir' ) ;
@@ -676,23 +715,7 @@ <h2>Event Testing</h2>
676715 gestureArea . addEventListener ( 'pointerdown' , handleGesture ) ;
677716 gestureArea . addEventListener ( 'wheel' , handleGesture ) ;
678717
679- // --- event 测试 ---
680- const eventElement = document . getElementById ( 'event-element' ) ;
681- const eventLog = document . getElementById ( 'event-log' ) ;
682-
683- const events = [
684- 'mousedown' , 'mouseup' , 'click' , 'dblclick' , 'mousemove' , 'mouseover' , 'mouseout' , 'mouseenter' , 'mouseleave' , 'contextmenu' , 'wheel' ,
685- 'touchstart' , 'touchend' , 'touchmove' , 'touchcancel' ,
686- 'pointerdown' , 'pointerup' , 'pointermove' , 'pointercancel' , 'pointerenter' , 'pointerleave' , 'pointerover' , 'pointerout' , 'gotpointercapture' , 'lostpointercapture'
687- ] ;
688-
689- function logEvent ( e ) {
690- eventLog . innerHTML = e . type + '<br>' + eventLog . innerHTML ;
691- }
692-
693- events . forEach ( function ( eventType ) {
694- eventElement . addEventListener ( eventType , logEvent ) ;
695- } ) ;
718+
696719 </ script >
697720</ body >
698721</ html >
0 commit comments