skip to Main Content

I have the following code in a HTML Block on a WordPress website:

<!DOCTYPE html>
<html lang="de">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Durchlaufendes Band aus Bildern mit CSS</title>

  <style>
    #bildband-container {
      overflow: hidden; 
      width: 100%;
    }

    
    #bildband {
      display: flex;
      animation: scroll 10s linear infinite; 
    }

    @keyframes scroll {
      0% {
        transform: translateX(0);
      }
      100% {
        transform: translateX(-100%);
      }
    }

    
    img {
      width: auto; 
      height: 300px; 
      object-fit: cover;
    }
  </style>
</head>
<body>

  <div id="bildband-container">
    <div id="bildband">
      <img src="url1" alt="">
      <img src="url2" alt="">
      <img src="url3" alt="">
    </div>
  </div>

</body>
</html>

It is supposed to scroll sideways through some images/logos in an infinite band.
The URLs are correct and it seems to work but stops after ~1.5 images and goes back to the start.
The images are all different sizes so that might be a problem since it worked when they were all set to the same width with auto height (width: 100px, height: auto).
Also if I adjust the height to something higher it stops even sooner. I honestly dont know what I am missing here.

I tried removing object-fit: cover; and using different scroll speeds and heights of the images. Also I triple checked the URLs were not the problem and even used the same image 3 times. Nothing changed.

2

Answers


  1. Replace the 10s with 200ms(or something less than 10s) to fast the animation. This decreases the duration of the whole animation.

    #bildband {
      display: flex;
      animation: scroll 10s linear infinite; 
    }
    

    This will automatically increase the speed!
    If the animation stop then add an 50% keyframe like this:

    @keyframes youranimation{
        0%{
             transform:translateX(0%);
        }
        50%{
             transform:translateX(-100%); 
        }
        100%{
            transform:translateX(0%);
        }
    }
    
    Login or Signup to reply.
  2. Just add more keyframes:

    @keyframes scroll {
          0% {
            transform: translateX(0);
          }
          25% {
            transform: translateX(25%);
          }
          50% {
            transform: translateX(50%);
          }
          75% {
            transform: translateX(75%);
          }
          100% {
            transform: translateX(-100%);
          }
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search