Skip to content

Commit f12fe75

Browse files
committed
Disable animation when hidden by v-click
1 parent 83df5ac commit f12fe75

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"vclick"
4+
]
5+
}

components/FancyArrow.vue

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ const { arrowSvg, textPosition } = useRoughArrow({
114114
: undefined,
115115
}
116116
: undefined,
117-
strokeAnimationKeyframeName: "rough-arrow-dash",
118-
fillAnimationKeyframeName: "rough-arrow-fill",
117+
strokeAnimationClass: "rough-arrow-stroke",
118+
fillAnimationClass: "rough-arrow-fill",
119119
});
120120
</script>
121121

@@ -137,15 +137,15 @@ const { arrowSvg, textPosition } = useRoughArrow({
137137
</svg>
138138
<div
139139
v-if="$slots.default && textPosition"
140+
class="rough-arrow-content"
140141
:style="{
141142
position: 'absolute',
142143
left: `${textPosition.x}px`,
143144
top: `${textPosition.y}px`,
144145
transform: 'translate(-50%, -50%)',
146+
animationDuration: `${props.animationDuration ?? DEFAULT_ANIMATION_DURATION}ms`,
147+
animationDelay: `${props.animationDelay ?? 0}ms`,
145148
visibility: animationEnabled ? 'hidden' : 'visible',
146-
animation: animationEnabled
147-
? `rough-arrow-content ${props.animationDuration ?? DEFAULT_ANIMATION_DURATION}ms ease-out ${props.animationDelay ?? 0}ms forwards`
148-
: 'none',
149149
}"
150150
>
151151
<slot />
@@ -168,6 +168,7 @@ const { arrowSvg, textPosition } = useRoughArrow({
168168
visibility: visible;
169169
}
170170
}
171+
171172
@keyframes rough-arrow-fill {
172173
to {
173174
visibility: visible;
@@ -185,4 +186,23 @@ const { arrowSvg, textPosition } = useRoughArrow({
185186
visibility: visible;
186187
}
187188
}
189+
190+
.rough-arrow-stroke {
191+
animation: rough-arrow-dash ease-out forwards;
192+
}
193+
.rough-arrow-fill {
194+
animation: rough-arrow-fill ease-out forwards;
195+
}
196+
.rough-arrow-content {
197+
animation: rough-arrow-content ease-out forwards;
198+
}
199+
.slidev-vclick-target.slidev-vclick-hidden .rough-arrow-stroke {
200+
animation: none;
201+
}
202+
.slidev-vclick-target.slidev-vclick-hidden .rough-arrow-fill {
203+
animation: none;
204+
}
205+
.slidev-vclick-target.slidev-vclick-hidden .rough-arrow-content {
206+
animation: none;
207+
}
188208
</style>

components/use-rough-arrow.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export function useRoughArrow(props: {
6767
duration?: number;
6868
delay?: number;
6969
};
70-
strokeAnimationKeyframeName: string;
71-
fillAnimationKeyframeName: string;
70+
strokeAnimationClass: string;
71+
fillAnimationClass: string;
7272
}) {
7373
const {
7474
point1: point1Ref,
@@ -81,8 +81,8 @@ export function useRoughArrow(props: {
8181
twoWay,
8282
centerPositionParam,
8383
animation,
84-
strokeAnimationKeyframeName,
85-
fillAnimationKeyframeName,
84+
strokeAnimationClass,
85+
fillAnimationClass,
8686
} = props;
8787
const baseOptions = {
8888
// We don't support the `bowing` param because it's not so effective for arc.
@@ -364,14 +364,18 @@ export function useRoughArrow(props: {
364364
const pathDelay =
365365
currentDelay +
366366
(index / segment.strokedPaths.length) * segmentDuration;
367-
path.style.animation = `${strokeAnimationKeyframeName} ${pathDuration}ms ease-out ${pathDelay}ms forwards`;
367+
path.classList.add(strokeAnimationClass);
368+
path.style.animationDuration = `${pathDuration}ms`;
369+
path.style.animationDelay = `${pathDelay}ms`;
368370
path.style.strokeDashoffset = `${segment.length}`;
369371
path.style.strokeDasharray = `${segment.length}`;
370372
path.style.visibility = "hidden";
371373
});
372374
currentDelay += segmentDuration;
373375
segment.filledPaths.forEach((path) => {
374-
path.style.animation = `${fillAnimationKeyframeName} ${segmentDuration}ms ease-out ${currentDelay}ms forwards`;
376+
path.classList.add(fillAnimationClass);
377+
path.style.animationDuration = `${segmentDuration}ms`;
378+
path.style.animationDelay = `${currentDelay}ms`;
375379
path.style.visibility = "hidden";
376380
});
377381
}

slides.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ If no snap target or absolute position is specified, the arrow will automaticall
716716
Animated
717717
</FancyArrow>
718718

719+
<FancyArrow x1="600" y1="100" x2="700" y2="200" animated v-click>
720+
Animated with v-click
721+
</FancyArrow>
722+
719723
<div mt-40 h-70>
720724

721725
```html {*}{maxHeight: '100%'}
@@ -739,6 +743,10 @@ If no snap target or absolute position is specified, the arrow will automaticall
739743
<FancyArrow x1="500" y1="100" x2="600" y2="200" animated>
740744
Animated
741745
</FancyArrow>
746+
747+
<FancyArrow x1="600" y1="100" x2="700" y2="200" animated v-click>
748+
Animated with v-click
749+
</FancyArrow>
742750
```
743751

744752
</div>

0 commit comments

Comments
 (0)