News:

Wondering if this will always be free?  See why free is better.

Main Menu

Scrolling css text

Started by Dave J, February 02, 2021, 05:23:49 AM

Previous topic - Next topic

Dave J

Hi all,

I have some scrolling text using css. The code (see below) works fine and the text does scroll across the screen except for a couple of things I'd like to change.

1. The time it takes for the text to start scrolling once its finished on the left side. Currently it seems to be around 10 seconds and I would like to reduce that to around 5 seconds
2. When the text is seen on a moblile or tablet if the original text is too long it cuts the text off rather than scroll though the whole message (the message in the code below is OK and it's not too long)

Can anyone help with changes please?

<style style="text/css">
.marquee {
height: 20px;
overflow: hidden;
position: relative;
color: yellow;
}
.marquee p {
position: absolute;
width: 100%;
height: 100%;
margin: 0;
line-height: 20px;
text-align: center;
font-size: 1.4em;
/* Starting position */
-moz-transform:translateX(100%);
-webkit-transform:translateX(100%);
transform:translateX(100%);
/* Apply animation to this element */
-moz-animation: scroll-left 30s linear infinite;
-webkit-animation: scroll-left 30s linear infinite;
animation: scroll-left 30s linear infinite;
}
/* Move it (define the animation) */
@-moz-keyframes scroll-left {
0%   { -moz-transform: translateX(100%); }
100% { -moz-transform: translateX(-100%); }
}
@-webkit-keyframes scroll-left {
0%   { -webkit-transform: translateX(100%); }
100% { -webkit-transform: translateX(-100%); }
}
@keyframes scroll-left {
0%   {
-moz-transform: translateX(100%); /* Browser bug fix */
-webkit-transform: translateX(100%); /* Browser bug fix */
transform: translateX(100%);
}
100% {
-moz-transform: translateX(-100%); /* Browser bug fix */
-webkit-transform: translateX(-100%); /* Browser bug fix */
transform: translateX(-100%);
}
}
</style>

<div class="marquee">
<p>Don't forget to tell your friends and family about us. Registration is free.</p>
</div>


If you want to see it working go to my site
If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

GigaWatt

Try changing these two values to 25s.

Code (before) Select

-moz-animation: scroll-left 30s linear infinite;
-webkit-animation: scroll-left 30s linear infinite;


Code (after) Select

-moz-animation: scroll-left 25s linear infinite;
-webkit-animation: scroll-left 25s linear infinite;


This is about the duration (10s --> 5s). About the cutoff... don't know :P.
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

Dave J

Thanks. I'll have a look and let you know.
If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

Dave J

Quote from: GigaWatt on February 02, 2021, 02:32:58 PM
Try changing these two values to 25s.

Code (before) Select

-moz-animation: scroll-left 30s linear infinite;
-webkit-animation: scroll-left 30s linear infinite;


Code (after) Select

-moz-animation: scroll-left 25s linear infinite;
-webkit-animation: scroll-left 25s linear infinite;


This is about the duration (10s --> 5s). About the cutoff... don't know :P.

Changing those lines makes no difference, even if I go as low as 5 for each.

The only line that makes a difference is animation: scroll-left 30s linear infinite the more I reduce that number the faster the text scrolls across the screen and that also reduces the repeat time, I have now set that to 20 which is readable and repeats about 7 secs which is better.

Now just to find out about the cutting off of the text on mobile devices.

Thanks for your help GigaWatt
If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

Dave J

OK I have now sorted the issue out. There was a lot of trial and error going on but I'm happy with it now.

I used the following code and not only does it repeat it repeats immediately after the text has finish on the left side with no wait time. I have also incorporated a hover function that pauses the scrolling text when the curser goes over it.

It also now scrolls the whole text even on mobile devices, so in thoery it doesn't matter how much text you insert in to it.

So I'm a happy bunny.

<style style="text/css">
.marquee {
  width: 100%;
  margin: 0 auto;
  white-space: nowrap;
  overflow: hidden;
  box-sizing: border-box;
  line-height: 25px;
  font-size: 1.3em;
  color: yellow;
}

.marquee span {
  display: inline-block;
  padding-left: 100%;
  will-change: transform;
  /* show the marquee just outside the paragraph */
  animation: marquee 25s linear infinite;
}

.marquee span:hover {
  animation-play-state: paused
}


/* Make it move */

@keyframes marquee {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(-100%, 0);
  }
}


/* Respect user preferences about animations */

@media (prefers-reduced-motion: reduce) {
  .marquee {
    white-space: normal
  }
  .marquee span {
    animation: none;
    padding-left: 0;
  }
}
</style>
<p class="marquee">
   <span>
       Why not get your family and friends to join us. All they need to do is click on the 'Register' button at the top of the page, it doesn't cost anything and we wont ask for any details they don't want to give us.
   </span>
   </p>
If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

GigaWatt

It's actually advisable to include the code you've removed from your css (the -moz-animation -webkit-animation) and just set it to the same values as animation ;). One is for Mozilla (Firefox... I'm not a coder, but I'm guessing Firefox is "special" regarding animation and/or marque) and the other is for Safari (also special in some way... I guess).
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

Dave J

Quote from: GigaWatt on February 03, 2021, 12:50:12 PM
It's actually advisable to include the code you've removed from your css (the -moz-animation -webkit-animation) and just set it to the same values as animation ;).

Yep done that, thanks again

If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

Advertisement: