Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Marquee for variable message lengths

Tags:

html

css

marquee

I am looking for marquee tag alternatives and found how to do this through css. However the messages I am using are of variable lengths, so is there an alternative to putting in the '45s' attribute to maybe 100% so that no matter how long or short the message is, the message will show all of the message and loop again once the message has been displayed?

.marquee {
  margin: 0 auto;
  white-space: nowrap;
  overflow: hidden;
  position: absolute;
  color: #ffffff;
  background-color: #000000;
  font-family: Arial Rounded MT Bold;
}

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


@keyframes marquee {
  from  { text-indent:  0%}
  to    { text-indent: -150% }
}
<p id="PassengerNews_Scrollbar" class="microsoft marquee" style="height: 95%;  width: 90%;left: 5%;top: 2%;font-size: 7%;">
  <span>|*NewsData*|</span>
</p>
like image 760
Jason De'Nousse Avatar asked Feb 26 '15 11:02

Jason De'Nousse


People also ask

What can I use instead of marquee?

Use CSS animation instead of <marquee> CSS animation enables you to create the marquee effect and make it user-friendly by using the prefers-reduced-motion media query to stop all animations for those who don't want them.

How do you stop a marquee automatically at a certain position?

what CSS code may be used to stop the marquee at the specific position automatically?? HTML: <marquee behavior="slide" direction="right" loop="1"> a moving text </marquee> CSS: marquee{ width: 80%; } //use the width to specify where it should stop in css.

How do you make a text marquee in CSS?

The marquees in CSS are created using the CSS animation property along with the @keyframes to manipulate the element and create the animation. Additionally, we need to use translateX() and translateY() in order to specify the path to the scrolling contents.

Is marquee tag deprecated?

<marquee>: The Marquee element. Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.


1 Answers

Use the jQuery.Marquee plugin (License: ISC). If you don't want to use the plugin, you can use following code snippet from the plugin to calculate the delay

// formula is to: (Width of the text node + width of the main container / Width of the main container) * speed;
o.duration = ((parseInt(elWidth, 10) + parseInt(containerWidth, 10)) / parseInt(containerWidth, 10)) * o.duration;

With o.duration initialized with 5000 meaning 5 seconds.

like image 58
koppor Avatar answered Oct 05 '22 13:10

koppor