Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery animate() function is delayed and runs slowly

When I call a JQuery animate() call, the browser delays it for ~1 sec, and it then runs very slowly.

JQuery code:

<script type="text/javascript">

    $(document).ready(function () {
        $("#header").load("global/html/header.html",function(){});
        $("#footer").load("global/html/footer.html",function(){});

        $(".navLI").hover(function() {
            $(this).animate({"backgroundColor": jQuery.Color(255, 51, 00, 255)}, 500);
            $(this).animate({"borderLeftColor": jQuery.Color(255, 51, 00, 255)}, 500);
        }, function () {
            $(this).animate({"backgroundColor": jQuery.Color(255, 255, 255, 255)}, 500);
        });
    });
</script>

All referenced libraries are imported

VIDEO: https://youtu.be/2NnDj_TGUNA

like image 887
randomnetcat Avatar asked Dec 31 '25 06:12

randomnetcat


1 Answers

Use CSS only:

.navLI{
  -webkit-transition: 0.3s;
          transition: 0.3s;
  background: rgba(255, 51, 255, 0.5);
}
.navLI:hover{
  background: rgba(255, 255, 51, 1);
}

Regarding your jQuery problem. you forgot to use .stop()

 $(this).stop().animate({"backgroundColor": jQuery.Color(255, 51, 0, 1)}, 500);
like image 192
Roko C. Buljan Avatar answered Jan 01 '26 18:01

Roko C. Buljan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!