I need to make a TV channel style information bar that goes from right to left. I have the text that comes from the database and as it is a long text would need to be looping. I'll use it on a webpage.
As you did not put more details in the question, follow a simple template that can serve you. Basically you need to create a "container" with overflow:hidden
and do the animation with @keyframes
.txt {
width: 10em;
height: 1.5em;
background-color: red;
color: #fff;
font-family: sans-serif;
font-size: 1rem;
line-height: 1.5em;
padding: 0.5em;
white-space: nowrap;
overflow: hidden;
}
.txt span {
padding-left: 100%;
display: inline-block;
animation: texto 10s linear infinite;
}
@keyframes texto {
0% {
transform: translate(0, 0);
}
100% {
transform: translate(-100%, 0);
}
}
<div class="txt"><span>URGENTE!!! - <strong>Bolso Mito vai te pegar</strong> se vc não colocar o código na pergunta!</span></div>
It has the jquery.marquee plugin that uses css3 to do the animation, as the marquee element is obsolete I think this is the best way. I found in codepen an example link
$('.marquee').marquee({
//speed in milliseconds of the marquee
duration: 5000,
//gap in pixels between the tickers
gap: 50,
//time in milliseconds before the marquee will start animating
delayBeforeStart: 0,
//'left' or 'right'
direction: 'left',
//true or false - should the marquee be duplicated to show an effect of continues flow
duplicated: true
});
.marquee {
width: 300px;
overflow: hidden;
border: 1px solid #ccc;
background: #ccc;
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery.marquee/1.3.1/jquery.marquee.min.js"></script>
<div class="marquee">jQuery marquee is the best marquee plugin in the world</div>