Which is the correct syntax to animate the box-shadow property with jQuery?
$().animate({?:"0 0 5px #666"});
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Direct answer
Using Edwin Martin’s jQuery plugin for shadow animation, which extends the
.animatemethod, you can simply use the normal syntax with "boxShadow" and every facet of that – color, the x- and y-offset, the blur-radius and spread-radius – gets animated. It includes multiple shadow support.Using CSS animations instead
jQuery animates by changing the
styleproperty of DOM elements, which can cause surprises with specificity and moves style information out of your stylesheets.I can’t find browser support stats for CSS shadow animation, but you might consider using JS to apply an animation-based class instead of handling the animation directly. For example, you can define a box-shadow animation in your stylesheet:
You can then use the native
animationendevent to synchronise the end of the animation with what you were doing in your JS code:Vanilla JS:
jQuery: