Skip to content

Commit c612179

Browse files
authored
Merge pull request #6 from davidparys/added-oneshot
- Updated `.once` and added `.oneshot` modifier descriptions in the modifiers documentation.
2 parents 3ba594d + 04b05ed commit c612179

File tree

3 files changed

+54
-17
lines changed

3 files changed

+54
-17
lines changed

docs/content/2.usage/3.modifiers.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ V-GSAP supports the above four main animation types.
2929

3030
### `.once`
3131

32-
allows to run the scrollTrigger only once
32+
Makes the animation play only once when scrolling down, and stay in its final state even when scrolling back up.
33+
34+
### `.once.reversible`
35+
36+
Similar to `.once` but will reverse the animation when scrolling back up, allowing it to play again when scrolling down.
37+
38+
::alert{type="info"}
39+
This is the default previous behavior of `.once`.
40+
::
41+
3342

3443
### `.markers`
3544

docs/pages/playground.vue

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,30 @@
233233
>
234234
<DemoComponent v-gsap.whenVisible.from="{ autoAlpha: 0, x: -50 }" />
235235
</BoxComponent>
236+
<BoxComponent
237+
code="v-gsap.whenVisible.once.from='{ autoAlpha: 0, rotate: -45, duration: 2 }'"
238+
title="Once (stays in final state)"
239+
>
240+
<DemoComponent
241+
v-gsap.whenVisible.once.from="{
242+
autoAlpha: 0,
243+
rotate: -45,
244+
duration: 2
245+
}"
246+
/>
247+
</BoxComponent>
248+
<BoxComponent
249+
code="v-gsap.whenVisible.once.reversible.from='{ autoAlpha: 0, rotate: -45, duration: 2 }'"
250+
title="Once Reversible (old behavior)"
251+
>
252+
<DemoComponent
253+
v-gsap.whenVisible.once.reversible.from="{
254+
autoAlpha: 0,
255+
rotate: -45,
256+
duration: 2
257+
}"
258+
/>
259+
</BoxComponent>
236260
<BoxComponent
237261
code="v-gsap.whenVisible.from='{ autoAlpha: 0, start: 'top 60%', end: 'bottom 40%' }'"
238262
title="Custom start/end"
@@ -337,8 +361,8 @@
337361
</div>
338362
<div class="Grid">
339363
<BoxComponent
340-
v-gsap.whenVisible.stagger.from="{ opacity: 0 }"
341-
code="v-gsap.whenVisible.stagger.from='{ opacity: 0 }'"
364+
v-gsap.whenVisible.stagger.from="{ opacity: 0, y: 50, stagger: 0.4 }"
365+
code="v-gsap.whenVisible.stagger.from='{ opacity: 0, y: 50, stagger: 0.4 }'"
342366
title="Default"
343367
>
344368
<DemoComponent />
@@ -635,4 +659,4 @@ section {
635659
@apply md:grid-cols-2 lg:grid-cols-3;
636660
}
637661
}
638-
</style>
662+
</style>

src/runtime/plugin.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const vGsapDirective = (
5050

5151
beforeMount(el, binding, vnode) {
5252
if (appType == 'vue') el.dataset.gsapId = uuidv4()
53-
if (!gsapContext) gsapContext = gsap.context(() => {})
53+
if (!gsapContext) gsapContext = gsap.context(() => { })
5454

5555
binding = loadPreset(binding, configOptions)
5656

@@ -133,15 +133,15 @@ function assignChildrenOrderAttributesFor(vnode, startOrder?): number {
133133
return []
134134
}
135135

136-
;(getChildren(vnode) || [])?.forEach((child: any) => {
137-
;(child?.dirs ? Array.from(child?.dirs) : [])?.forEach((dir: any) => {
138-
if (dir.modifiers.timeline) return
136+
; (getChildren(vnode) || [])?.forEach((child: any) => {
137+
; (child?.dirs ? Array.from(child?.dirs) : [])?.forEach((dir: any) => {
138+
if (dir.modifiers.timeline) return
139139

140-
dir.modifiers[`suggestedOrder-${order}`] = true
141-
order++
140+
dir.modifiers[`suggestedOrder-${order}`] = true
141+
order++
142+
})
143+
order = assignChildrenOrderAttributesFor(child, order)
142144
})
143-
order = assignChildrenOrderAttributesFor(child, order)
144-
})
145145
return order
146146
}
147147

@@ -175,7 +175,11 @@ function prepareTimeline(el, binding, configOptions) {
175175
scrub,
176176
...callbacks,
177177
markers,
178-
toggleActions: once ? 'play none none reverse' : undefined,
178+
toggleActions: binding.modifiers.once
179+
? binding.modifiers.reversible
180+
? 'play none none reverse'
181+
: 'play none none none'
182+
: undefined,
179183
}
180184
}
181185

@@ -284,9 +288,9 @@ function prepareTimeline(el, binding, configOptions) {
284288
}
285289
const speed
286290
= speeds[
287-
Object.keys(binding.modifiers).find(modifier =>
288-
Object.keys(speeds).includes(modifier),
289-
) || ''
291+
Object.keys(binding.modifiers).find(modifier =>
292+
Object.keys(speeds).includes(modifier),
293+
) || ''
290294
] || 2
291295
timeline.to(el, { text: { value, speed } })
292296
}
@@ -425,4 +429,4 @@ function getValueFromModifier(binding, term: string) {
425429
return Object.keys(binding.modifiers)
426430
?.find(m => m.toLowerCase().includes(term.toLowerCase()))
427431
?.split('-')?.[1]
428-
}
432+
}

0 commit comments

Comments
 (0)