CSS3 Animation Delay longer than Duration breaks animation -
i attempting animate element display:none;opacity:0;
display:block;opacity:1;
. while below animation works, when introduce delay animation find cannot set delay value higher animation duration value. when do, animation ignored.
how set delay take e.g. 2 seconds , animation duration 300ms without breaking?
div p + p { display: none; opacity: 0; } div p:hover + p { display: block; opacity: 1; /* browser prefixes removed brevity */ -webkit-animation: fadeinfromnone 300ms 900ms linear; animation: fadeinfromnone 300ms 900ms linear; } div.working p:hover + p { display: block; opacity: 1; /* browser prefixes removed brevity */ -webkit-animation: fadeinfromnone 300ms 300ms linear; animation: fadeinfromnone 300ms 300ms linear; } @-webkit-keyframes fadeinfromnone { 0% { display: none; opacity: 0; } 1% { display: block ; opacity: 0; } 100% { display: block ; opacity: 1; } } keyframes fadeinfromnone { 0% { display: none; opacity: 0; } 1% { display: block ; opacity: 0; } 100% { display: block ; opacity: 1; } }
<div> <p>hover on me (broken)</p> <p>peek-a-boo</p> </div> <div class="working"> <p>hover on me (working)</p> <p>peek-a-boo</p> </div>
this boils down timing issue.
initially p has display:none;
, opacity:0;
. on hover p has display:block;
, opacity:1;
, , then, after delay, reset display:none;
, opacity:0;
when animation starts.
by setting hover p have display:block;
, animating opacity, desired result. stop animation completing , setting p opacity:0
again add forwards
attribute animation:
div p + p { display: none; opacity: 0; } div p:hover + p { display: block; /* browser prefixes removed brevity */ -webkit-animation: fadeinfromnone 300ms linear 900ms forwards; animation: fadeinfromnone 300ms linear 900ms forwards; } @-webkit-keyframes fadeinfromnone { { opacity:0; } { opacity:1; } } keyframes fadeinfromnone { { opacity:0; } { opacity:1; } }
<div> <p>hover on me</p> <p>peek-a-boo</p> </div>
Comments
Post a Comment