Weird trailing effect during css animation - css

I am creating an animation while I got this weird issue. Below is a code snippet with a single div with some styles and animation applied to it.
When I run the code, during the animation, I can see a weird trailing effect on the extreme right side of the square.
*{
margin: 0px;
padding: 0px;
}
body{
background-image: radial-gradient(pink, hotpink);
height: 100vh;
width: 100vw;
display: flex;
justify-content:center;
align-items: center;
}
#keyframes zoominout{
0%{
transform: scale(1.0);
}
50%{
transform: scale(1.1);
}
100%{
transform: scale(1.0);
}
}
#outer{
border: 2px solid black;
height: 450px;
width: 450px;
animation: zoominout infinite 4s;
}
<div id="outer"></div>
Whenever I click anywhere or press any button, the trails disappear.
What could be causing this and how should I solve this issue?
Also, this issue occurs only with borders. Without borders, no issue is there.
Update - This issue is with chrome browser only. While using firefox, no trailing lines are visible.

It appears to be your borders that are scaling but somehow remain behind in faded form.
If we take a more minimal example - no border radius, no flexing, you can see it clearly on this square. The first has animation duration 4s and shows separate lines which is what you get but in small form on the circle. The second has animation duration 40s and show more continuous as would be expected as more frames would be possible in the time.
Here's the snippet:
<style>
#keyframes zoominout{
0%{
transform: scale(1.0);
}
50%{
transform: scale(1.1);
}
100%{
transform: scale(1.0);
}
}
#outer{
border: 2px solid black;
border-color: magenta;
height: 450px;
width: 450px;
animation: zoominout infinite 4s;
background-color: cyan;
}
</style>
<div id="outer"></div>
So, what to do about it? Somehow the borders aren't totally disappearing but are fading.
Update: here's a quick workaround - animating dimensions rather than scaling. I know it's not the best way to animate (as it possibly isn't using the GPU???) but it seems to work. Of course you'd want to put your circle (now a square) into a container which has the actual width and then use %s. It worked on Chrome, Edge, Firefox on Windows 10 and Safari and Chrome on IOS14. It also removed the slight flicker that was previously seen on Firefox and Safari [which had both worked better on the initial code than Edge or Chrome on Win10].
Snippet with workaround:
<style>
*{
margin: 0px;
padding: 0px;
}
body{
background-image: radial-gradient(pink, hotpink);
height: 100vh;
width: 100vw;
display: flex;
justify-content:center;
align-items: center;
}
#keyframes zoominout{
0%{
width: var(--w);
height: var(--w);
}
50%{
width: calc(var(--w) * 1.1);
height: calc(var(--w) * 1.1);
}
100%{
width: var(--w);
height: var(--w);
}
}
#outer{
--w: 450px;/* you don't have to use a CSS variable but this is just to make it easier to change the width/height if you need to */
border: 2px solid black;
height: var(--w);
width: var(--w);
animation: zoominout infinite 4s;
}
</style>
<div id="outer"></div>

Related

CSS3 Animation: How do I create smooth movement of background image? Seems to be a Chrome only issue

Trying to smoothly animate a div's background image #bg2 over a short pixel distance (while a clip path animates over it). I'm not able to get the image to move smoothly, it jitters and judders. The clip path animation is fine.
I've tried different easing (linear / ease-in-out etc) suggested in another SO thread, and also extending the distance it needs to move, but it still seems to jump pixel by pixel (sort of), rather than move smoothly. (Although, extending the move distance isn't an option in the actual use case).
How can smooth movement of the cat background image #bg2 be accomplished? Thanks.
** Edit: It's totally smooth for me in Firefox, for me it's jittery in Chrome 91.0.4472.114 on Mojave 10.14.6, and less jittery in Safari. For other it seems to be smooth on Chrome also. Hmmm...
var clickTag = "#";
#main-container {
position: absolute;
width: 970px;
height: 250px;
left:-200px;
box-sizing: border-box;
background: #333;
overflow:hidden; perspective: 800px;
border:1px solid #ccc;
}
div, img {
position: absolute;
background-repeat:no-repeat;
width: 970px;
height: 250px;
z-index: 4;
background-size: 970px 250px;
}
#bg2{
width: 970px;
height: 250px;
z-index:2;
background-image:url('https://i.stack.imgur.com/6EcDu.jpg');
-webkit-clip-path: circle(9% at 682px 110px);
clip-path: circle(9% at 682px 110px);
transform: translateY(20px);
background-position: -5px -10px;
}
#bg2{animation: grow 2.5s 2.5s cubic-bezier(0.215, 0.610, 0.355, 1.000) forwards;-webkit-animation: groww 2.5s 2.5s cubic-bezier(0.215, 0.610, 0.355, 1.000) forwards;}
#-webkit-keyframes groww {
0% {opacity:1;transform: translateY(20px);clip-path: circle(9% at 682px 110px);-webkit-clip-path: circle(9% at 682px 110px);background-position: -5px -10px;}
100% {opacity:1;transform: translateY(-4px);clip-path: circle(15% at 682px 128px);-webkit-clip-path: circle(15% at 682px 128px);background-position: 0px 0px;}
}
#keyframes grow {
0% {opacity:1;transform: translateY(20px);clip-path: circle(9% at 682px 110px);background-position: -5px -10px;}
100% {opacity:1;transform: translateY(-4px);clip-path: circle(15% at 682px 128px);background-position: 0px 0px;}
}
<a href="javascript:window.open(window.clickTag)">
<div id="main-container" class="animate">
<div id="bg2"></div>
</div>
</a>
I'm a bit curious about why having a large banner while not displaying it all.
Anyways, I provide another way of animating, basically just changing the height. Hopefully that could give some ideas.
I removed the width to make it slightly more responsive.
The animation somewhat jittery in this solution, but I guess that it depends on your bezier curve. So perhaps that's the issue all along?
var clickTag = "#";
#main-container {
position: relative;
height: 250px;
box-sizing: border-box;
border: 1px solid #ccc;
background-color: #333;
}
#bg2 {
position: absolute;
left: 75%;
top: 50%;
transform: translate(-50%, -50%);
height: 40%;
aspect-ratio: 1;
border-radius: 50%;
background-image: url('https://i.stack.imgur.com/6EcDu.jpg');
background-position: right 25% center;
animation: grow 2.5s 2.5s cubic-bezier(0.215, 0.610, 0.355, 1.000) forwards;
}
#keyframes grow {
to { height: 80%; }
}
<a href="javascript:window.open(window.clickTag)">
<div id="main-container">
<div id="bg2"></div>
</div>
</a>

why is the background animation glitching over the foreground box on some browsers?

I am having a peculiar issue with a page in which an animated background item at times overlaps over the element in front.
I have seen this happen only on the Samsung Internet Browser (v13.2.1.70) so far.
I can't replicate it on chrome for example (I didn't test many other browsers either).
Here's a codepen of the issue: https://codepen.io/antizio/pen/qBqbqVX.
HTML
<div id="scene">
<div id="bg"></div>
<div id="card"></div>
</div>
CSS
#scene {
width: 500px;
height: 500px;
background: lightgreen;
}
#bg {
position: absolute;
left: 100px;
top: 260px;
width: 100px;
height: 100px;
background: red;
z-index: 10;
}
#card {
position: absolute;
width: 300px;
height: 300px;
background: radial-gradient(rgba(140, 193, 63, 0.5) 0%, #138849 70%);
transform: scale3d(0,0,1);
animation: scaleup infinite ease-in 2s;
}
#keyframes scaleup {
from {
transform: scale3d(0, 0, 1);
}
to {
transform: scale3d(1,1,1);
}
}
I have seen it sometimes behaving correctly sometimes overlapping, all just by changing the scrolling position of the page :/
I managed to fix the issue by adding an "empty" transform to the foreground element, however that's not ideal. I based this on remnants of browser behaviors from a long time ago.
Does anybody have any insight on this? Why does this happen? Is there a better way to fix this?

Scale animation breaks border radius when zoomed in and out

I am running the following code snippet:
#mydiv{
width: 2px;
height: 2px;
border-radius: 50%;
display: inline-block;
margin: 100px;
background-color: red;
animation: wave 1s infinite;
}
#keyframes wave{
0%{
transform: scale(1, 1);
}
100%{
transform: scale(100, 100);
}
}
<div id="mydiv"></div>
Normally this animation runs fine. The problem occurs when I zoom in and out my screen. After zooming in and then zooming out I see that border-radius starts getting incorrectly shown. I have taken two screenshots of how it gets:
The first image is taken on Microsoft Edge. It happened when I zoomed in and out using CTRL+ and CTRL-. Doing the same thing in Chrome also resulted in something exactly like this. The second one happened when I zoomed in and out using Chrome dev tools. I have also experienced this in the android version of Chrome (that's where I noticed it first). It didn't happen in Firefox.
I don't know why it happens, but my guess is, zooming in and out suddenly affects the calculation of CSS transform.
What is the actual reason of this bug? Is there a fix for it?
Try this
#mydiv{
width: 200px;
height: 200px;
border-radius: 50%;
display: inline-block;
margin: 100px;
background-color: red;
animation: wave 1s infinite;
}
#keyframes wave{
0%{
transform: scale(0);
}
100%{
transform: scale(1);
}
}
<div id="mydiv"></div>

Make a CSS3 animation go backwards

Hey guys I have a CSS3 animation which makes a pulsing effect using #keyframes animation .The problem is that the animation starts from 0% to 100% every time and I want to start from 0% to 100% and after 100% to 0% so the pulsing effect to have a continuity.The ball should increase to the full size and after slowly decrese to the initial size and after increase again and decrese and so on.
<html>
<head>
<title>Pulse effect</title>
<style>
/*Border radius 50% to make it round */
#circle{
position: relative;
width: 50px;
height: 50px;
border:2px solid red;
border-radius: 50%;
}
#circle:after{
content: '';
width: 20px;
height: 20px;
display: block;
left:50%;
margin-left: -10px;
top:50%;
margin-top: -10px;
background-color: hsla(41, 97%, 47%,1);
border-radius: 50%;
position: absolute;
/*Use keyframe animation to manipulate the effect */
animation:pulseone 2s infinite;
}
#keyframes pulseone{
/*Use SCALE value from TRANSFORM method to increse/decrese the x,y of the vector */
0% {transform:scale(1,1);
background-color: hsla(41,97%,47%,1);}
/*25%{transform:scale(1.4,1.4);
background-color: hsla(41,97%,47%,.9);}
50%{transform:scale(1.8,1.8);
background-color:hsla(41,97%,47%,.8);}
75%{trasform:scale(2.2,2.2);
background-color: hsla(41,97%,47%,.7);}*/
100%{transform:scale(2.5,2.5);
background-color: hsla(41,97%,47%,.6);}
}
</style>
</head>
<body>
<div id="circle"></div>
</body>
</html>
Use animation-direction: alternate to get the effect you are after.
In the shorthand you have, just add the alternate keyword:
animation:pulseone 2s infinite alternate;

Animation-play-state not playing nice with animation-delay in Safari

I am working on modifying this example in some ways for use in my application. This works awesome in Chrome and FF, but in Safari, not so much. If you look you will see in Chrome the pie charts look as expected, but in Safari they are all "whole".
The css (copied from the example) looks like this:
.pie {
display: inline-block;
position: relative;
width: 100px;
line-height: 100px;
border-radius: 50%;
background: yellowgreen;
background-image: linear-gradient(to right, transparent 50%, #655 0);
color: transparent;
text-align: center;
}
#keyframes spin {
to { transform: rotate(.5turn); }
}
#keyframes bg {
50% { background: #655; }
}
.pie::before {
content: '';
position: absolute;
top: 0; left: 50%;
width: 50%; height: 100%;
border-radius: 0 100% 100% 0 / 50%;
background-color: inherit;
transform-origin: left;
animation: spin 50s linear infinite, bg 100s step-end infinite;
animation-play-state: paused; <-- Safari's issue
animation-delay: inherit;
}
I noted the second-to-last line in the code to identify the problem. When animation-play-state is set to paused, Safari will not put the animation in the initial condition set by animation-delay. Chrome and FF seem to look at the animation-delay, put the animation in the state it would be at that delay, and then stay paused.
Is there a workaround I am missing where Safari will put the animation in the initial condition and then stay paused?

Resources