skip to Main Content

I am trying to make a container that has children Horizontally and moves from left to right
Each of those children , when it reach the end of the container => goes to the start of the container
let’s imagine that it contain 4 children:

  0% :  ..1 | 2 | 3 | 4..    
 25% :  ..4 | 1 | 2 | 3..  
 50% :  ..3 | 4 | 1 | 2..  
 75% :  ..2 | 3 | 4 | 1..  
100% :  ..1 | 2 | 3 | 4..

not like the carousel, but like the ring rolling (smooth )
for infinite time

Below

.container {
  height: 200px;
  width: 800px;
  border: 1px solid #333;
  overflow: hidden;
  margin: 25px auto;
}

.box {
  background: orange;
  height: 180px;
  margin: 10px;
  animation-name: move;
  animation-duration: 10s;
  animation-iteration-count: infinite;
  animation-direction: right;
  animation-timing-function: linear;
  display: flex;
}

.card {
  background: #fff;
  height: 150px;
  min-width: 100px;
  margin: 15px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.box:hover {
  animation-play-state: paused;
}

@keyframes move {
  0% {
    margin-left: 000px;
  }
  25% {
    margin-left: 100px;
  }
  50% {
    margin-left: 200px;
  }
  75% {
    margin-left: 300px;
  }
  100% {
    margin-left: 400px;
  }
}
<div class="container">
  <div class="box">
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
  </div>
</div>

is the code I have tried:

may use JavaScript.

2

Answers


  1. Chosen as BEST ANSWER

    here is the soulutiion I get from varpex :

    ul {
        --d: 10s;
        /* duration */
        display: grid;
        gap: 10px;
        grid-template-columns: repeat(4, 1fr);
        /* number of visible images */
        overflow: hidden;
        mask: linear-gradient(90deg, #0000, #000 5% 95%, #0000);
        -webkit-mask: linear-gradient(90deg, #0000, #000 5% 95%, #0000);
        margin: 0;
        padding: 0;
        list-style: none;
    }
    
    ul>li {
        grid-area: 1/1;
        animation: r var(--d) linear infinite;
        font-family: system-ui;
        font-size: 1.3rem;
        padding: 1rem;
        border: 0.5rem solid #0000;
        background: orange padding-box;
        text-align: center;
        border-radius: 1rem;
    }
    
    ul>li:nth-child(2) {
        animation-delay: calc(-0.1428571429*var(--d));
    }
    
    ul>li:nth-child(3) {
        animation-delay: calc(-0.2857142857*var(--d));
    }
    
    ul>li:nth-child(4) {
        animation-delay: calc(-0.4285714286*var(--d));
    }
    
    ul>li:nth-child(5) {
        animation-delay: calc(-0.5714285714*var(--d));
    }
    
    ul>li:nth-child(6) {
        animation-delay: calc(-0.7142857143*var(--d));
    }
    
    ul>li:nth-child(7) {
        animation-delay: calc(-0.8571428571*var(--d));
    }
    
    @keyframes r {
        14.2857142857% {
            transform: translate(-100%);
        }
    
        14.2957142857% {
            transform: translate(600%);
        }
    }
    <h1 style="text-align: center">Infinite Scroll Animation</h1>
        <div class="scroller" data-speed="fast">
            <ul class="tag-list scroller__inner">
                <li >HTML</li>
                <li >CSS</li>
                <li >JS</li>
                <li >SSG</li>
                <li >webdev</li>
                <li >animation</li>
                <li >UI/UX</li>
            </ul>
        </div>

    it works good and beautifully.


  2. Check this and let me know if this works 🙂

    .container {
      height: 200px;
      width: 500px;
      border: 1px solid #333;
      overflow: hidden;
      margin: 25px auto;
        background: orange;
    
    }
    
    .box {  
      display: flex;
      height: 180px;
      position: relative;
      animation-name: move;
      animation-duration: 5s;
      animation-iteration-count: infinite;
      animation-direction: right;
      animation-timing-function: cubic-bezier(1,2,3,1); //linear
    
    }
    
    .card {
      background: #fff;
      height: 150px;
      min-width: 100px;
      margin: 15px;
      border-radius: 10px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
    
    .box:hover {
      animation-play-state: paused;
    }
    
    @keyframes move {
      0% {
        left: -515px;
      }
      100% {
        left: 0px;
      }
    }
    <div class="container">
      <div class="box">
        <div class="card"></div>
        <div class="card"></div>
        <div class="card"></div>
        <div class="card"></div>
        <div class="card"></div>
        <div class="card"></div>
        <div class="card"></div>
        <div class="card"></div>
         <div class="card"></div>
          <div class="card"></div>
      </div>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search