CodexBloom - Programming Q&A Platform

jQuery .animate() optimization guide as expected on CSS custom properties in Chrome

👀 Views: 85 💬 Answers: 1 📅 Created: 2025-08-25
jquery css animation javascript

I'm wondering if anyone has experience with Hey everyone, I'm running into an issue that's driving me crazy... I'm collaborating on a project where I'm maintaining legacy code that I've searched everywhere and can't find a clear answer. I'm experiencing a puzzling scenario with jQuery's `.animate()` method when trying to animate CSS custom properties (variables) in Chrome. The animation works perfectly in Firefox, but in Chrome, it doesn't seem to update the property values correctly. Here's a simplified version of my code: ```javascript $(document).ready(function() { $('#animateBtn').on('click', function() { $('#box').css('--box-color', 'red'); $('#box').animate({ '--box-color': 'blue' }, { duration: 1000, step: function(now, fx) { $(this).css('--box-color', now); } }); }); }); ``` In this example, I’m trying to animate a custom property `--box-color` from red to blue. The box's background color is set using this variable. While the box color changes instantly when I set it directly through the `css()` method, the animation doesn't transition smoothly in Chrome. Instead, it just jumps to the final color without any transition effect. I've confirmed that my Chrome is up to date (version 115.0.5790.98) and I’ve checked that jQuery is at version 3.6.0. I also tested this in an incognito window to rule out any extension conflicts, but the scenario continues. Is there something I'm missing with how jQuery interacts with CSS custom properties in Chrome? Any insights or workarounds would be greatly appreciated! I'm working on a CLI tool that needs to handle this. What's the best practice here? For context: I'm using Javascript on Debian. Any advice would be much appreciated. I'm developing on macOS with Javascript. I'd be grateful for any help. I appreciate any insights! The project is a application built with Javascript. Hoping someone can shed some light on this. I've been using Javascript for about a year now. Thanks for taking the time to read this!