This does do the delays but doesn’t seem to apply the style changes until the end:
for (i=20;i>=0;i--) {
var boxShadow = i+"px "+i+"px "+i+"px #888";
$('article').css("box-shadow", boxShadow);
sleep(20);
}
function sleep(ms)
{
var dt = new Date();
dt.setTime(dt.getTime() + ms);
while (new Date().getTime() < dt.getTime());
}
This doesn’t apply the delays at all:
for (i=20;i>=0;i--) {
var boxShadow = i+"px "+i+"px "+i+"px #888";
$('article').delay(500).css("box-shadow", boxShadow);
}
Can this be done more easily with css3 transitions? Am I just making some small jquery error in the delay sample?
Thank you to anyone who can help.
You can use classes and
setTimeoutto utilize CSS3 transitions for your animation effect:CSS —
I used
allfor the transition declarations because of Chrome… some versions of Chrome use-webkit-box-shadowand newer versions usebox-shadow.allisn’t a big deal if you aren’t changing any other properties of the element (or if you want to animate those property changes).JS —
Here is a demo: http://jsfiddle.net/jasper/tvfPq/1/
Note that in the demo I used two
box-shadows:box-shadow : 0 0 24px #000, inset 0 0 24px #999;