-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 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
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,45 @@ | ||
<template> | ||
<div class="container"> | ||
<div class="ball" ref="ballRef"></div> | ||
<input type="range" min="0" max="1" step="0.01" v-model="range" @input="changeFn"> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { onMounted, ref } from 'vue' | ||
const ballRef = ref<HTMLDivElement | null>(null) | ||
const range = ref(0.5) | ||
const changeFn = () => { | ||
ballRef.value?.style.setProperty('--delay', `-${range.value}s`) | ||
// ballRef.value!.style['animation-play-state'] = 'running' | ||
} | ||
onMounted(() => { | ||
changeFn() | ||
}) | ||
</script> | ||
<style> | ||
.container { | ||
position: relative; | ||
width: 100px; | ||
height: 100px; | ||
} | ||
.ball { | ||
--delay: 0s; | ||
width: 50px; | ||
height: 50px; | ||
background: red; | ||
border-radius: 50%; | ||
margin-bottom: 50px; | ||
animation: move ease-in-out forwards 1s paused; | ||
animation-delay: var(--delay); | ||
} | ||
@keyframes move { | ||
50% { | ||
transform: translateX(100px) scale(1.5); | ||
} | ||
to { | ||
transform: translateX(200px) scale(0.8); | ||
} | ||
} | ||
</style> |
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,11 @@ | ||
# 利用延迟实现复杂动画 | ||
::: tip 思路 | ||
巧用 `animation-delay` 负数实现复杂动画,上代码: | ||
::: | ||
|
||
<<< @/code/demo/AnimationByDelay.vue{vue} | ||
|
||
<script setup> | ||
import AnimationByDelay from '../code/demo/AnimationByDelay.vue' | ||
</script> | ||
<AnimationByDelay /> |