-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POLISH(lottie): Continue to play lottie when mouseleave
- Loading branch information
Showing
2 changed files
with
69 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<template lang="pug"> | ||
vue3-lottie( | ||
ref="com" | ||
v-bind="$props" | ||
@mouseenter="handleMouseenter" | ||
@mouseleave="handleMouseleave" | ||
@onComplete="handleComplete" | ||
) | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
export interface LottieProps { | ||
animationData: any | ||
animationLink: string | ||
loop: boolean | number | ||
autoPlay: boolean | ||
rendererSettings: any | ||
width: number | string | ||
height: number | string | ||
speed: number | ||
delay: number | ||
direction: string | ||
pauseOnHover: boolean | ||
playOnHover: boolean | ||
backgroundColor: string | ||
pauseAnimation: boolean | ||
} | ||
const props = withDefaults(defineProps<LottieProps>(), { | ||
speed: 1, | ||
autoPlay: false | ||
}) | ||
const { isMobile } = useDevice() | ||
const isPlaying = ref(false) | ||
const needNextPlay = ref(false) | ||
const com = ref<any>(null) | ||
const handleMouseenter = (event: Event) => { | ||
if (isMobile || !com.value || isPlaying.value) { | ||
needNextPlay.value = true | ||
return | ||
} | ||
isPlaying.value = true | ||
needNextPlay.value = true | ||
com.value?.play() | ||
} | ||
const handleMouseleave = (event: Event) => { | ||
const target = event.target | ||
if (target === com.value?.$el) { | ||
needNextPlay.value = false | ||
} | ||
} | ||
const handleComplete = () => { | ||
if (needNextPlay.value) { | ||
com.value?.stop() | ||
com.value?.play() | ||
} else { | ||
isPlaying.value = false | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43eebf9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
affine-pro – ./
affine-pro-git-production-toeverything.vercel.app
affine.pro
affine-pro-toeverything.vercel.app