-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJS.js
32 lines (27 loc) · 1.07 KB
/
JS.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
//get data from the 🤟 StreamElements 🤟 data injection
const name = '{{name}}';
const amount = '{{amount}}';
const money = '{{currency}}{{amount}}';
const sender = '{{sender}}';
const animation = 'rubberBand';
// vanilla es6 query selection (can use libraries and frameworks too)
const userNameContainer = document.querySelector('#name');
const amountContainer = document.querySelector('#amount');
const moneyContainer = document.querySelector('#money');
const senderContainer = document.querySelector('#sender');
// change the inner html to animate it 🤪
userNameContainer.innerHTML = stringToAnimatedHTML(name, animation);
amountContainer.innerHTML = stringToAnimatedHTML(amount, animation);
/**
* return an html, with animation
* @param s: the text
* @param anim: the animation to use on the text
* @returns {string}
*/
function stringToAnimatedHTML(s, anim) {
let stringAsArray = s.split('');
stringAsArray = stringAsArray.map((letter) => {
return `<span class="animated-letter ${anim}">${letter}</span>`
});
return stringAsArray.join('');
}