There seems to be an issue with my DIV element. When hovering, the background color changes to blue. However, when a button is clicked, a class is added which animates the background color to green. After this animation, the hover effect no longer works and the background does not change to blue as expected.
Why is this happening?
HTML:
<div class="box"></div>
<button class="animate-btn">Animate</button>
CSS:
.box {
background-color: red;
width: 200px;
height: 200px;
}
.box:hover {
background-color: blue;
}
.trigger-bg-change {
-webkit-animation: bg-change 1s ease 0 1 forwards;
animation: bg-change 1s ease 0 1 forwards;
}
@-webkit-keyframes bg-change {
0% {background-color:red;}
100% {background-color:green;}
}
@-keyframes bg-change {
0% {background-color:red;}
100% {background-color:green;}
}
JS:
$(function() {
$('.animate-btn').on('click', function() {
console.log('hey');
$('.box').addClass('trigger-bg-change');
});
});