var container = document.querySelector(".container")
var light = document.getElementById("light");
var dark = document.getElementById("dark");
light.addEventListener('click', lightMode);
function lightMode(){
container.style.backgroundColor = "white";
container.style.color = "black";
}
dark.addEventListener('click', darkMode);
function darkMode() {
container.style.backgroundColor = "black";
container.style.color = "white";
}
It is my code, please tell me how can I add transition when a user clicks on dark mode.
Now, It is switching very fastly which is not attractive for user and for me also.
Please tell me if you know
I’m Expecting the transition to be added when I switch from dark mode to light mode
It Should not instantly change it. It must have a transition of 1s ease in
3
Answers
The ease timing function is set to 1s at tag, you can adjust it as you need.
Here is the complete answer
You can achieve this by adding CSS transitions and toggling classes using JavaScript.
Check code below:
You should now have a smooth transition when switching between light mode and dark mode. Feel free to customize the styles and transition duration according to your preferences.