r/css•
spl4299

How does one keep the drop-shadow anchored while an image rotates?

I've just begun using and understanding CSS. I've gotten along pretty well (although my CSS organization and condensing is pretty rough), and I've run into a few issues that I'm not sure how to resolve.

When using a drop shadow on a shaped PNG image, to give it a defined shadow. If I then animate that image in CSS, is there any way to keep the shadow in one place, still spinning with the image? As of right now the shadow spins around with the image.

Is there any way to fix this issue using CSS? or is it something I would have to do with another approach? This is part of the code I've been playing with:

@-webkit-keyframes spinTryAngle
{
	from 
	{
		-webkit-transform: rotate(0deg);
	}
	to 
	{
		-webkit-transform: rotate(359deg);
	}
}
img.one
{
	position: relative;
	left: 43px;
	display: block;
	
	-webkit-animation-name: spinTryAngle;
    -webkit-animation-duration: 950ms;
    -webkit-animation-iteration-count: 3;
    -webkit-animation-timing-function: ease-in-out;
	-webkit-animation-delay: 500ms;
	
    -webkit-filter: drop-shadow(10px 10px 5px rgba(0, 0, 0, .3));

}

Also, here is a JSFiddle link for what I'm talking about

Thanks for any and all help!

EDIT: Fixed the non working link

EDIT2: thanks to u/8bitsquid and u/ForScale for all assistance and ideas.

Updated JSFiddle: https://jsfiddle.net/o5u9yb30/5/

Posted Sep 4, 2015, 3:52 PM UTC · edited

1313
ForScale•
3
spl4299OP•

I guess in one way that does resolve the issue but not exactly what I was hoping for

1
ForScale•

What needs to be changed to bring it in line with what you were hoping for?

2
spl4299OP•

I was hoping for a drop-shadow behind the image, giving it a raised appearance from the background. Still keeping with the outline of the shape behind it, just as the image rotates, instead of the shadow following the image in a circle, stay at one fixed point on the page.

1
ForScale•

I'll give it another go!

1
8bitsquid•

You may be to use two triangle elements. One for the graphic and another for the shadow - stacked with the "shadow" element slightly offset - then rotate them simultaneously.

It may be possible to animate the shadow offset to make it appear as if there is a static light source, but that may require JS and you'd have to bring some trig into the mix to get the proper x,y.

[edit] Here's a rough example. Maybe not perfect, but an ok shadow simulation: https://jsfiddle.net/o5u9yb30/4/. I moved the shadow further away so its easier to see the effect (the off-center rotate made it harder to tell from only 10px offset).

2
spl4299OP•

I was just thinking about that actually. Just using two elements instead of drop-shadow. I was just curious if there was a pure CSS thing that I could be missing and unable to find.

1