Home > Software engineering >  Moving text immediately
Moving text immediately

Time:09-22

I tried to create an infinite loop for my text that will start on the screen. But everything that I found is to start off the screen and to come in to screen. After that everything is perfect as I need, but that starting point ruins my concept.

I know that we have some HTML tag that can move text, but it can't help me either.

.text1{
  animation: move 5s linear 2.5s infinite;
  transform: translateX(-100%);
}

*{
  margin: 0;
  padding:0;
}

.wrapper{
  display: flex;
}

@keyframes move{
  from{
    transform: translateX(-100%);
  }
  
   to{
     transform: translateX(100%);
   }
}

.text2{
  position: absolute;
  animation: move 5s linear 0s infinite;
}

.text1,.text2{
  font-size: 80px;
   white-space: nowrap;
}
<div >
  
<div >Lorem ipsum dolor sit amet. </div>

<div >Lorem ipsum dolor sit amet.</div>

</div>

And i also don't like that horizontal scroll, so if any chance to remove it.

CodePudding user response:

You can do this in multiple different ways, but your attempt is okay, so I just fixed it as you need. And for that horizontal scroll you just need to set overflow-x to hidden, you can do that on some parent div. I set it to the whole body, but you can change it.

.text1{
  animation: move 5s linear 2.5s infinite;
  transform: translateX(-100%);
}

*{
  margin: 0;
  padding:0;
}

.wrapper{
  display: flex;
}

body{
  overflow-x: hidden;
}

@keyframes move{
  from{
    transform: translateX(100%);
  }
  
   to{
     transform: translateX(-100%);
   }
}

.text2{
  position: absolute;
  animation: move 5s linear 0s infinite;
}

.text1,.text2, .text3{
  font-size: 50px;
   white-space: nowrap;
}

.text3{
  position: absolute;
   animation: move2 2.5s linear 0s;
     animation-fill-mode: forwards;

}

@keyframes move2{
  from{
    transform: translateX(0%);
  }
  
   to{
     transform: translateX(-100%);
   }
}
<div >
  
<div >Lorem ipsum dolor sit amet. </div>

<div >Lorem ipsum dolor sit amet.</div>

<div >Lorem ipsum dolor sit amet.</div>

</div>

  • Related