I'm making a dark mode button using an icon font and I was wondering if there's a way to have a smooth transition when changing from one icon to the next? The colors have a smooth transition, so that's not a problem, but the icons are changing faster than the colors. Here's the code:
$(document).ready(function() {
$('.daynight').click(function() {
$('body').toggleClass('night');
$('.daynight span').toggleClass('th-sun');
});
});
body.night {
background: #292f36;
color: white!important;
}
.daynight span {
cursor: pointer;
padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="daynight"><span class="th th-moon"></span></div>
I'm using transition: color 0.3s ease-in-out, background-color 0.4s ease-in-out; in my body tag to get the color transitions.