so, i have 5 cards in my project, how do i make them slide slowly and completely towards the left and pop out at the same pace from the right side of the screen and keep moving till they reach their default position and halt for a few seconds and then continue.
I tried some css, but it is not working satisfactorily:
.box {
background: #beeec9a6;
animation: slide 20s infinite;
animation-timing-function: linear;
}
@keyframes _slide_ {
0% {
transform: translateX(100%);
}
15% {
transform: translateX(0%);
}
85% {
transform: translateX(0%);
}
100% {
transform: translateX(-100%);
}
}
they are moving towards the left alright but not completely… Please anyone ?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Hi there,
I could suggest trying out the following CSS:
Here is an example app that I’ve tested this with and it seems to be working as expected:
Here is this in action:
Hope that this helps!
Best,
Bobby
Hey @ca9aa8543ef8472cb226cc4661df64,
From your description, it seems you want to create a carousel-like effect where the cards scroll continuously from right to left, pause for a moment in their original position, then start moving again.
Looking at your keyframes, there are a couple of things that might be causing issues.
First, you’re moving your element from 100% (completely off the right side of the screen) to 0% (back in its original position) quite fast (within the first 15% of the animation duration).
Second, the element stays at 0% (in its original position) for a large chunk of the animation (from 15% to 85%) and then it quickly moves to -100% (completely off the left side of the screen).
In your case, it may be beneficial to have the element spend more time moving and less time stationary.
Here is an updated version of your keyframes animation:
In this version, the element starts moving immediately from off the right side of the screen (100%) and spends 25% of the animation duration moving to its original position (0%). It then stays in place from 25% to 75% of the animation duration. Finally, it spends the last 25% of the animation moving off the left side of the screen (-100%).
This should give a smoother movement and make it more likely for the element to move fully off the screen.
If you want the cards to spend more time in their original position, you can adjust the percentages accordingly. Just make sure that the movement phases (from 100% to 0% and from 0% to -100%) take up a sufficient portion of the animation duration to allow the cards to move fully off screen.
You might also want to check whether the parent container of your
.box
elements has the styleoverflow: hidden;
to ensure that the cards disappear when they move off screen. Without this, the cards might still be partially visible, giving the impression that they haven’t moved fully off screen.Remember to adjust the animation duration (
20s
in your example) to achieve the desired speed of movement. If the movement is still too fast, you can increase this value