Created
September 18, 2022 19:55
-
-
Save CodeWizardGenius/21352d5fb0d309fd8da1dc4c3e3ac269 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MOODS = { | |
'π€¬': { max: 1 }, | |
'π‘': { max: 10 }, | |
'π ': { max: 20 }, | |
'π¦': { max: 30 }, | |
'βΉοΈ': { max: 40 }, | |
'π': { max: 50 }, | |
'π': { max: 60 }, | |
'π': { max: 70 }, | |
'π': { max: 80 }, | |
'π': { max: 90 }, | |
'π': { max: 100 }, | |
'π': { min: 100 } | |
}, | |
_MOOD = document.getElementById('mood'), | |
_FORM = _MOOD.parentNode, | |
_MOUT_CURRENT = document.getElementById('current'), | |
_MOUT_PREVIOUS = document.getElementById('previous'); | |
let val = null; | |
let curMout = ''; | |
function updateVal() { | |
let newval = +_MOOD.value; | |
if (val !== newval) { | |
_FORM.style.setProperty('--val', val = newval); | |
for (let k in MOODS) | |
if ((!MOODS[k].min || (MOODS[k].min <= val)) && | |
(!MOODS[k].max || (MOODS[k].max > val))) { | |
// Check if value needs to be changed | |
if (k !== curMout) { | |
_MOUT_PREVIOUS.textContent = _MOUT_CURRENT.textContent; | |
_MOUT_CURRENT.textContent = k; | |
curMout = k; | |
// Restart animation | |
_MOUT_PREVIOUS.style.animation = "none"; | |
_MOUT_PREVIOUS.style.animation = null; | |
} | |
break | |
} | |
} | |
}; | |
export default updateVal; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment