Skip to content

Instantly share code, notes, and snippets.

@CodeWizardGenius
Created September 18, 2022 19:55
Show Gist options
  • Save CodeWizardGenius/21352d5fb0d309fd8da1dc4c3e3ac269 to your computer and use it in GitHub Desktop.
Save CodeWizardGenius/21352d5fb0d309fd8da1dc4c3e3ac269 to your computer and use it in GitHub Desktop.
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