Code Pope
Code Pope

Reputation: 5449

Animation of text-shadow in CSS

I have the following code where I do an animation in CSS moving a div. But I wanted to also animate the shadow of the text simulating somehow a weight for my text:

div#main {
    background-color: #2E2E2E;
}

div#lblCaption {
    margin-bottom: 0px;
    color: #C7C7C7;}
    
div#NodeCaptionContainer{     
    animation-duration: .7s;
    animation-name: fadeAndScale;
    animation-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
}
@keyframes fadeAndScale {
    from {
        opacity: 0;
		transform: scale(.9, .9);
		text-shadow: 0 0 .75px rgb(255, 255, 255), 0 0 .75px rgb(255, 255, 255);
    }
    to {
        opacity: 1;
        transform: scale(1, 1);
		text-shadow: 0 0 .0px rgb(255, 255, 255), 0 0 .0px rgb(255, 255, 255);
    }
}
<div id="main">
  <div id="NodeCaptionContainer">
          <div id="lblCaption" class="pretty p-default p-thick p-pulse"><p class="noMargin">&nbsp;&nbsp;&nbsp;&nbsp;Node: 1:9 &nbsp;&nbsp;&nbsp;&nbsp; Type: Function &nbsp;&nbsp;&nbsp;&nbsp; Read: 480B &nbsp;&nbsp;&nbsp;&nbsp; Write: 1088B &nbsp;&nbsp;&nbsp;&nbsp; </p></div> 
  </div> 
</div>

The problem is that the animation for the translation is done smoothly by the animation-timing-function, but not for the shadow. I wanted to also smooth the shadow transition. Is there a way to smooth also the shadow transition in the CSS?

Upvotes: 4

Views: 1627

Answers (1)

Liam
Liam

Reputation: 6743

https://jsfiddle.net/Liamm12/6d9p5uun/67/

Defined text-shadow in NodeCaptionContainer and use forwards to not get back to the same code of NodeCaptionContainer then hide it using keyframes

div#main {
    background-color: #2E2E2E;
}

div#lblCaption {
    margin-bottom: 0px;
    color: #C7C7C7;}
    
div#NodeCaptionContainer{     
    -webkit-animation: fadeAndScale .7s ease-in-out forwards;
    animation: fadeAndScale .7s ease-in-out forwards;
    text-shadow: 0 0 .75px red, 0 0 .75px red;
}
@keyframes fadeAndScale {
    from {
        opacity: 0;
		transform: scale(.9, .9);
    }
    to {
        opacity: 1;
        transform: scale(1, 1);
		text-shadow: 0 0 0 rgb(255, 255, 255);
    }
}
<div id="main">
  <div id="NodeCaptionContainer">
          <div id="lblCaption" class="pretty p-default p-thick p-pulse"><p class="noMargin">&nbsp;&nbsp;&nbsp;&nbsp;Node: 1:9 &nbsp;&nbsp;&nbsp;&nbsp; Type: Function &nbsp;&nbsp;&nbsp;&nbsp; Read: 480B &nbsp;&nbsp;&nbsp;&nbsp; Write: 1088B &nbsp;&nbsp;&nbsp;&nbsp; </p></div> 
  </div> 
</div>

Upvotes: 1

Related Questions