100-project-100-days-website/100_projects/81-emoji-range-slider/main.js

34 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-05-13 08:50:20 +03:00
const body = document.querySelector("body");
const emoji = document.querySelector(".slide-emoji");
const input = document.querySelector("input");
const bar = document.querySelector(".progress-bar");
const thumb = document.querySelector(".thumb");
input.oninput = ()=>{
let sliderValue = input.value;
thumb.style.left = sliderValue + '%';
bar.style.width = sliderValue + '%';
if(sliderValue < 20){
emoji.style.marginTop = "0px";
body.classList.add("angry");
body.classList.remove("confuse");
body.classList.remove("like");
}
if(sliderValue >= 20){
emoji.style.marginTop = "-140px";
body.classList.add("confuse");
body.classList.remove("angry");
body.classList.remove("like");
}
if(sliderValue >= 40){
emoji.style.marginTop = "-280px";
}
if(sliderValue >= 60){
emoji.style.marginTop = "-420px";
body.classList.add("like");
body.classList.remove("confuse");
body.classList.remove("angry");
}
if(sliderValue >= 80){
emoji.style.marginTop = "-560px";
}
}