I have a problem with a repeating CSS animation that is executed by a jquery hover function. You can see an example of the problem in this DEMO.
When you open the demo please hover over the first star and pan the mouse from left to right. As you can see the animation repeats itself causing a stutter. How can I fix this so that the animation only fire once per star, keeping the previous stars highlighted.
HTML
<div class="GvStarContainer">
<!--Style 1 STARTED-->
<div class="GvStarTmp">
<div class="margi-star">
<div class="rate-ex1-cnt">
<div id="1" class="star star-one-1 rate-btn star-one"></div>
<div id="2" class="star star-one-2 rate-btn star-one"></div>
<div id="3" class="star star-one-3 rate-btn star-one"></div>
<div id="4" class="star star-one-4 rate-btn star-one"></div>
<div id="5" class="star star-one-5 rate-btn star-one"></div>
</div>
</div>
</div>
<!--Style 1 FINISHED-->
<!--Style 2 STARTED-->
<div class="GvStarTmp">
<div class="margi-star">
<div class="rate-ex2-cnt">
<div id="1" class="star star-two-1 rate-btn star-two"></div>
<div id="2" class="star star-two-2 rate-btn star-two"></div>
<div id="3" class="star star-two-3 rate-btn star-two"></div>
<div id="4" class="star star-two-4 rate-btn star-two"></div>
<div id="5" class="star star-two-5 rate-btn star-two"></div>
</div>
</div>
</div>
<!--Style 2 FINISHED-->
<!--Style 3 STARTED-->
<div class="GvStarTmp">
<div class="margi-star">
<div class="rate-ex3-cnt">
<div id="1" class="star star-tree-1 rate-btn star-tree"></div>
<div id="2" class="star star-tree-2 rate-btn star-tree"></div>
<div id="3" class="star star-tree-3 rate-btn star-tree"></div>
<div id="4" class="star star-tree-4 rate-btn star-tree"></div>
<div id="5" class="star star-tree-5 rate-btn star-tree"></div>
</div>
</div>
</div>
<!--Style 3 FINISHED-->
</div>
JS
$(document).ready(function() {
var prevStars = $(this).prevAll();
var nextStars = $(this).nextAll();
$(".star").hover(
function() {
var prevStars = $(this).prevAll();
prevStars.addClass('rate-btn-hover');
},
function() {
var prevStars = $(this).prevAll();
prevStars.removeClass('rate-btn-hover');
}
);
$("body").on("click", ".star", function() {
var prevStars = $(this).prevAll().addBack();
prevStars.addClass('rate-btn-active');
});
});