Credits Correct way to animate box-shadow with jQuery
Solution # 1 - JQuery:
You can check out Edwin Martin's jQuery plugin for shadow animation. It extends the .animate
method, so you can simply use the normal syntax with "boxShadow" and every facet of that like color, the x- and y-offset, the blur-radius and spread-radius:
$(selector).animate({ boxShadow : "0 0 5px 3px rgba(100,100,200,0.4)" });
Solution # 2 - CSS:
#my-div{
position:absolute;
top: 50px;
left: 50px;
height: 100px;
width: 100px;
background-color: #eee;
animation: shadowThrob 5s;
animation-direction: alternate;
-webkit-animation: shadowThrob 5s;
-webkit-animation-direction: alternate;
}
/* Standard syntax */
@keyframes shadowThrob {
from {box-shadow: 0 0 30px 10px rgba(190,65,12, 0.9);}
to {box-shadow: 0 0 30px 10px rgba(190,65,12, 0.2);}
}
/* Chrome, Safari, Opera */
@-webkit-keyframes shadowThrob {
from {box-shadow: 0 0 30px 10px rgba(190,65,12, 0.9);}
to {box-shadow: 0 0 30px 10px rgba(190,65,12, 0.2);}
}
EDIT
Changed this:
/* Standard syntax */
animation: shadowThrob 5s;
/* Chrome, Safari, Opera */
-webkit-animation: shadowThrob 5s;
To make it stop after 5 seconds... Also added some comments for browser compatibility in the code
JSFiddle: (Updated)
link