-
Notifications
You must be signed in to change notification settings - Fork 0
/
toggle-on-beat.js
36 lines (32 loc) · 1014 Bytes
/
toggle-on-beat.js
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
35
36
AFRAME.registerComponent('toggle-on-beat', {
schema: {
analyserEl: { type: 'selector' },
beat: { default: 'low' },
component: { default: '' },
property: { default: 'visible' },
value1: { default: true },
value2: { default: false },
},
init: function () {
const analyserEl = this.data.analyserEl || this.el;
const el = this.el;
const data = this.data;
data.toggleState = true;
analyserEl.addEventListener(`audioanalyser-beat-${this.data.beat}`, function () {
data.toggleState = !data.toggleState;
if (data.toggleState == true) {
if (data.component !== '') {
el.setAttribute(data.component, data.property, data.value1);
} else {
el.setAttribute(data.property, data.value1);
}
} else {
if (data.component !== '') {
el.setAttribute(data.component, data.property, data.value2);
} else {
el.setAttribute(data.property, data.value2);
}
}
});
},
});