Skip to content

Commit 7f04819

Browse files
authored
111 fix build anim (#113)
* fix: fix build animation * feat: add interval to build anim
1 parent a652b51 commit 7f04819

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

src/AnimationConfig.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface AnimationConfig {
55
type: string
66
delay?: number
77
duration?: number
8+
interval?: number
89
transformOrigiin?: string
910
}
1011

@@ -84,3 +85,19 @@ export function applyInAnimations(el: any, config: ConfigItem) {
8485
}
8586
}
8687
}
88+
89+
export function applyStepAnimation(
90+
animation: AnimationConfig,
91+
to: number,
92+
target: any,
93+
prop: string,
94+
) {
95+
target[prop] = 1
96+
const config: any = {
97+
duration: animation.interval ? animation.interval * to - 1 : (animation.duration ?? 0.1 * to),
98+
ease: `steps(${to})`,
99+
delay: animation.delay,
100+
}
101+
config[prop] = to
102+
gsap.to(target, config)
103+
}

src/components/RecursiveComponent.vue

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ParentComponent from './ParentComponent.vue'
1111
import LoadingComponent from './LoadingComponent.vue'
1212
import LCARSMarkdown from './LCARSMarkdown.vue'
1313
import gsap from 'gsap'
14-
import type { AnimationConfig } from '@/AnimationConfig'
14+
import { applyStepAnimation, type AnimationConfig } from '@/AnimationConfig'
1515
import TextComponent from './TextComponent.vue'
1616
1717
const props = useAttrs()
@@ -126,12 +126,7 @@ function triggerAnimations() {
126126
if (props.childrenAnimation) {
127127
const animation = props.childrenAnimation as AnimationConfig
128128
if (animation.type === 'build') {
129-
gsap.to(animated, {
130-
duration: animation.duration ?? 0.1 * children.length,
131-
children: children.length,
132-
ease: `steps(${children.length})`,
133-
delay: animation.delay,
134-
})
129+
applyStepAnimation(animation, children.length, animated, 'children')
135130
}
136131
} else {
137132
animated.children = children.length
@@ -142,12 +137,7 @@ function triggerAnimations() {
142137
if (props.topChildrenAnimation) {
143138
const animation = props.topChildrenAnimation as AnimationConfig
144139
if (animation.type === 'build') {
145-
gsap.to(animated, {
146-
duration: animation.duration ?? 0.1 * topChildren.length,
147-
top: topChildren.length,
148-
ease: `steps(${topChildren.length})`,
149-
delay: animation.delay,
150-
})
140+
applyStepAnimation(animation, topChildren.length, animated, 'top')
151141
}
152142
} else {
153143
animated.top = topChildren.length
@@ -158,12 +148,7 @@ function triggerAnimations() {
158148
if (props.bottomChildrenAnimation) {
159149
const animation = props.bottomChildrenAnimation as AnimationConfig
160150
if (animation.type === 'build') {
161-
gsap.to(animated, {
162-
duration: animation.duration ?? 0.1 * bottomChildren.length,
163-
bottom: bottomChildren.length,
164-
ease: `steps(${bottomChildren.length})`,
165-
delay: animation.delay,
166-
})
151+
applyStepAnimation(animation, bottomChildren.length, animated, 'bottom')
167152
}
168153
} else {
169154
animated.bottom = bottomChildren.length
@@ -174,12 +159,7 @@ function triggerAnimations() {
174159
if (props.leftChildrenAnimation) {
175160
const animation = props.leftChildrenAnimation as AnimationConfig
176161
if (animation.type === 'build') {
177-
gsap.to(animated, {
178-
duration: animation.duration ?? 0.1 * leftChildren.length,
179-
left: leftChildren.length,
180-
ease: `steps(${leftChildren.length})`,
181-
delay: animation.delay,
182-
})
162+
applyStepAnimation(animation, leftChildren.length, animated, 'left')
183163
}
184164
} else {
185165
animated.left = leftChildren.length
@@ -190,12 +170,7 @@ function triggerAnimations() {
190170
if (props.rightChildrenAnimation) {
191171
const animation = props.rightChildrenAnimation as AnimationConfig
192172
if (animation.type === 'build') {
193-
gsap.to(animated, {
194-
duration: animation.duration ?? 0.1 * rightChildren.length,
195-
right: rightChildren.length,
196-
ease: `steps(${rightChildren.length})`,
197-
delay: animation.delay,
198-
})
173+
applyStepAnimation(animation, rightChildren.length, animated, 'right')
199174
}
200175
} else {
201176
animated.right = rightChildren.length

0 commit comments

Comments
 (0)