Skip to content

Commit 871eb65

Browse files
move JS code for bar element into main script
1 parent 7fff2e3 commit 871eb65

File tree

3 files changed

+303
-317
lines changed

3 files changed

+303
-317
lines changed

assets/src/js/animator.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ const duration = 600
22
const easeOutQuad = t => t * (2 - t)
33

44
function css (element, styles) {
5-
for (const property in styles) {
6-
if (!styles.hasOwnProperty(property)) {
7-
continue
8-
}
9-
5+
for (const property of Object.keys(styles)) {
106
element.style[property] = styles[property]
117
}
128
}
@@ -89,17 +85,13 @@ function toggle (element, animation) {
8985
}
9086
}
9187

92-
function animate (element, targetStyles, fn) {
88+
function animate (element, targetStyles, callbackFn) {
9389
let startTime = null
9490
const styles = window.getComputedStyle(element)
9591
const diff = {}
9692
const startStyles = {}
9793

98-
for (const property in targetStyles) {
99-
if (!targetStyles.hasOwnProperty(property)) {
100-
continue
101-
}
102-
94+
for (const property of Object.keys(targetStyles)) {
10395
// calculate step size & current value
10496
const to = parseFloat(targetStyles[property])
10597
const current = parseFloat(styles[property])
@@ -117,22 +109,19 @@ function animate (element, targetStyles, fn) {
117109
if (!startTime) startTime = timestamp
118110
const progress = Math.min((timestamp - startTime) / duration, 1.00)
119111

120-
for (const property in diff) {
121-
if (!diff.hasOwnProperty(property)) {
122-
continue
123-
}
124-
112+
for (const property of Object.keys(diff)) {
125113
const suffix = property !== 'opacity' ? 'px' : ''
126114
element.style[property] = startStyles[property] + (diff[property] * easeOutQuad(progress)) + suffix
127115
}
128116

117+
// keep going until animation finished
129118
if (progress < 1.00) {
130119
return window.requestAnimationFrame(tick)
131120
}
132121

133122
// animation finished!
134-
if (fn) {
135-
fn()
123+
if (callbackFn) {
124+
callbackFn()
136125
}
137126
}
138127

assets/src/js/bar.js

Lines changed: 0 additions & 298 deletions
This file was deleted.

0 commit comments

Comments
 (0)