Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove a sharp start?

I just got acquainted with animation in CSS. And I ran into the problem that it is not possible to do smoothly so that the animation goes in cycles and is not interrupted.
I tried a lot of different options and through crutches. There were even successful solutions.
But seeing examples of smooth animations that are looped and without any jumps, I can’t figure out how to do it. At the same time, the RGB gradient did not find a smooth transition. ((Why didn’t I consider JS, because I liked smooth animations on pure CSS3, I wanted to try it on it, but I’m already ready to use JS, the main thing is to see how it’s done) (I hope everything is clear in the description, otherwise I used a translator)

If anyone knows, please tell me

div {
    display: block;
    background: linear-gradient(#FF3155, #FF3155, #FFAF42, #FFAF42, #FFED5E, #FFED5E, #FF3155);
    background-size: cover;
    width: 500px;
    height: 500px;
    animation: gradient 5s infinite linear; 
}
@keyframes gradient {
     to {
         background-position: 0 100vh;
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div>
        
    </div>
</body>
</html>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your final background position should match the height of the DIV:

div {
    display: block;
    background: linear-gradient(#FF3155, #FF3155, #FFAF42, #FFAF42, #FFED5E, #FFED5E, #FF3155);
    background-size: cover;
    width: 500px;
    height: 500px;
    animation: gradient 5s infinite linear; 
}
@keyframes gradient {
    to {
         background-position: 0 500px;
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div>
        
    </div>
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading