@@ -231,6 +231,19 @@ function onMouseMove(e: MouseEvent) {
231231 mouseY = e .clientY
232232}
233233
234+ function onTouchMove(e : TouchEvent ) {
235+ const touch = e .touches [0 ]
236+ if (touch ) {
237+ mouseX = touch .clientX
238+ mouseY = touch .clientY
239+ }
240+ }
241+
242+ function onTouchEnd() {
243+ mouseX = - 9999
244+ mouseY = - 9999
245+ }
246+
234247function onMouseLeave() {
235248 mouseX = - 9999
236249 mouseY = - 9999
@@ -254,6 +267,9 @@ function start() {
254267onMounted (() => {
255268 window .addEventListener (' resize' , onResize )
256269 window .addEventListener (' mousemove' , onMouseMove )
270+ window .addEventListener (' touchstart' , onTouchMove , { passive: true })
271+ window .addEventListener (' touchmove' , onTouchMove , { passive: true })
272+ window .addEventListener (' touchend' , onTouchEnd )
257273 document .addEventListener (' mouseleave' , onMouseLeave )
258274 nextTick (() => {
259275 requestAnimationFrame (() => start ())
@@ -265,6 +281,9 @@ onUnmounted(() => {
265281 cancelAnimationFrame (animationId )
266282 window .removeEventListener (' resize' , onResize )
267283 window .removeEventListener (' mousemove' , onMouseMove )
284+ window .removeEventListener (' touchstart' , onTouchMove )
285+ window .removeEventListener (' touchmove' , onTouchMove )
286+ window .removeEventListener (' touchend' , onTouchEnd )
268287 document .removeEventListener (' mouseleave' , onMouseLeave )
269288})
270289 </script >
0 commit comments