forked from Okazari/Rythm.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDancer.js
More file actions
34 lines (30 loc) · 956 Bytes
/
Dancer.js
File metadata and controls
34 lines (30 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pulse from './dances/pulse.js'
import shake from './dances/shake.js'
import jump from './dances/jump.js'
import twist from './dances/twist.js'
import vanish from './dances/vanish.js'
import color from './dances/color.js'
class Dancer {
constructor() {
this.dances = {}
this.registerDance('size', pulse)
this.registerDance('pulse', pulse)
this.registerDance('shake', shake)
this.registerDance('jump', jump)
this.registerDance('twist', twist)
this.registerDance('vanish', vanish)
this.registerDance('color', color)
}
registerDance(type, value) {
this.dances[type] = value
}
dance(type, className, ratio, options) {
let dance = type
if( typeof type === 'string' ) {
dance = this.dances[type] || this.dances['pulse']
}
const elements = document.getElementsByClassName(className)
Array.from(elements).forEach(elem => dance(elem, ratio, options))
}
}
export default new Dancer