I have a div, 'marqueeContainer', that is acting as a scrolling marquee. In this div I have another div with the id of 'marquee'. In THIS div, I have three divs, LineA, LineB and LineC. The contents of these lines will be dynamic, loaded in from a database.
I am currently using CSS animation to scroll the 'marquee' from right to left, with it's parent 'marqueeContainer' having a fixed width, and the overflow set to hidden.
The problem that I'm running into is that when the amount of text in each LINE div is quite lengthy, the text will overlap.
INCLUDED JFIDDLE
How do I modify the CSS so that each line stays a single line, each div stays inline with the rest and does NOT overlap, and the animation is a seamless loop, no matter the length of the text inside each LINE div?
HTML:
<div id="marqueeContainer">
<div id="marquee" class="loaded">
<span class="line" id="lineA"><span class="title">The Singer's Musical Theatre Anthology: Mezzo-Soprano/Belter, Volume 1 Book/Audio</span> - <span class="artist">Happy to Keep His Dinner Warm from "How to Succeed in Business without Really Trying" (accompaniment)</span> | <span class="album">Ruben Piirainen, piano</span></span>
<span class="line" id="lineB"><span class="title">The Singer's Musical Theatre Anthology: Mezzo-Soprano/Belter, Volume 1 Book/Audio</span> - <span class="artist">Happy to Keep His Dinner Warm from "How to Succeed in Business without Really Trying" (accompaniment)</span> | <span class="album">Ruben Piirainen, piano</span></span>
<span class="line" id="lineC"><span class="title">The Singer's Musical Theatre Anthology: Mezzo-Soprano/Belter, Volume 1 Book/Audio</span> - <span class="artist">Happy to Keep His Dinner Warm from "How to Succeed in Business without Really Trying" (accompaniment)</span> | <span class="album">Ruben Piirainen, piano</span></span>
</div>
</div>
CSS:
body{
font-family: Arial, sans-serif;
}
#marqueeContainer{
width: 570px;
height: 30px;
position: relative;
overflow: hidden;
padding: 0;
margin: 0;
top: 20px;
left: 47px;
pointer-events: none;
}
#marquee{
visibility:visible;
display: block;
position: absolute;
overflow: hidden;
width: 300%;
height: 30px;
pointer-events: none;
}
#marquee > span{
pointer-events: none;
}
#marquee.loaded{
-webkit-animation: marquee 10s linear infinite;
-moz-animation: marquee 10s linear infinite;
-ms-animation: marquee 10s linear infinite;
-o-animation: marquee 10s linear infinite;
animation: marquee 10s linear infinite;
pointer-events: none;
}
#marquee span.line{
display: none;
}
#marquee.loaded span.line{
display: inline-block;
float: left;
width: 33.333%;
padding-top: 6px;
color: rgba(0,0,0, 0.6);
font-size: 9pt;
white-space: nowrap;
}
#-webkit-keyframes marquee {
0% { left: -50%; }
100% { left: -150%; }
}
#-moz-keyframes marquee {
0% { left: -50%; }
100% { left: -150%; }
}
#-ms-keyframes marquee {
0% { left: -50%; }
100% { left: -150%; }
}
#-o-keyframes marquee {
0% { left: -50%; }
100% { left: -150%; }
}
#keyframes marquee {
0% { left: -50%; }
100% { left: -150%; }
}
add width: 100%; in place of width:33.33%; to #marquee.loaded span.line
add height: 100%; in place of height:30px; to #marquee
add height:30px; in place of height: 30px; to #marqueeContainer
edit: not the best solution since the marquee does not execute a perfect loop due to the text elements no longer being inline.
So after doing some research, I found a potential solution:
If you are okay with using jQuery in your project, there is a jQuery plugin you can use that might help:
<script type='text/javascript' src='//cdn.jsdelivr.net/jquery.marquee/1.3.1/jquery.marquee.min.js'></script>
I sketched out an example of something similar to what you are looking for:
Codepen Example
HTML:
<div class="marquee">
<span class="line" id="lineA"><span class="title">The Singer's Musical Theatre Anthology: Mezzo-Soprano/Belter, Volume 1 Book/Audio</span> - <span class="artist">Happy to Keep His Dinner Warm from "How to Succeed in Business without Really Trying" (accompaniment)</span> | <span class="album">Ruben Piirainen, piano</span></span>
<span class="line" id="lineB"><span class="title">The Singer's Musical Theatre Anthology: Mezzo-Soprano/Belter, Volume 1 Book/Audio</span> - <span class="artist">Happy to Keep His Dinner Warm from "How to Succeed in Business without Really Trying" (accompaniment)</span> | <span class="album">Ruben Piirainen, piano</span></span>
<span class="line" id="lineC"><span class="title">The Singer's Musical Theatre Anthology: Mezzo-Soprano/Belter, Volume 1 Book/Audio</span> - <span class="artist">Happy to Keep His Dinner Warm from "How to Succeed in Business without Really Trying" (accompaniment)</span> | <span class="album">Ruben Piirainen, piano</span></span>
</div>
CSS:
.marquee {
width: 570px;
overflow: hidden;
}
.marquee span.line{
padding-top: 6px;
color: rgba(0,0,0, 0.6);
font-size: 9pt;
}
JS:
$('.marquee').marquee({
//speed in milliseconds of the marquee
duration: 15000,
//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
});
reference: http://aamirafridi.com/jquery/jquery-marquee-plugin
rather than add more external code into something I wish to keep as lightweight as possible. I have decided to keep this in the HTML and CSS. The problem I was having was BOTH in the CSS and HTML, not just the CSS. Rather than have three (3) spans, I consolidated everything into one (1) span, but repeated the content three times to ensure everything would stay on one line.
The #marquee's width is set to auto. where the span.line's width is set to 100%. No white-space: nowrap needed.
And so far, I have an ever expandable marquee that loops quite seamlessly by using only HTML and CSS
HERE'S MY FIDDLE
HTML:
<div id="marqueeContainer">
<div id="marquee" class="loaded">
<span class="line">The Singer's Musical Theatre Anthology: Mezzo-Soprano/Belter, Volume 1 Book/Audio - Diamonds Are a Girl's Best Friend from "Gentlemen Prefer Blondes" (accompaniment) | Ruben Piirainen, piano The Singer's Musical Theatre Anthology: Mezzo-Soprano/Belter, Volume 1 Book/Audio - Diamonds Are a Girl's Best Friend from "Gentlemen Prefer Blondes" (accompaniment) | Ruben Piirainen, piano The Singer's Musical Theatre Anthology: Mezzo-Soprano/Belter, Volume 1 Book/Audio - Diamonds Are a Girl's Best Friend from "Gentlemen Prefer Blondes" (accompaniment) | Ruben Piirainen, piano </span>
</div>
</div>
CSS:
body{
font-family: Arial, sans-serif;
}
#marqueeContainer{
width: 570px;
height: 25px;
position: relative;
overflow: hidden;
padding: 0;
margin: 0;
top: 20px;
left: 47px;
}
#marquee{
visibility:visible;
display: block;
position: absolute;
overflow: hidden;
width: auto;
height: 100%;
top: 0;
left: 0;
}
#marquee.loaded span.line{
-webkit-animation: marquee 10s linear infinite;
-moz-animation: marquee 10s linear infinite;
-ms-animation: marquee 10s linear infinite;
-o-animation: marquee 10s linear infinite;
animation: marquee 10s linear infinite;
}
#marquee.loaded span.line{
display: block;
width: auto;
padding-top: 6px;
color: rgba(0,0,0, 0.6);
font-size: 9pt;
white-space: nowrap;
position: relative;
top: 0;
}
#-webkit-keyframes marquee {
0% { left: -17%; }
100% { left: -50.4%; }
}
#-moz-keyframes marquee {
0% { left: -17%; }
100% { left: -50.4%; }
}
#-ms-keyframes marquee {
0% { left: -17%; }
100% { left: -50.4%; }
}
#-o-keyframes marquee {
0% { left: -17%; }
100% { left: -50.4%; }
}
#keyframes marquee {
0% { left: -17%; }
100% { left: -50.4%; }
}
Related
I am unable to debug on iphones, was hoping someone would be able to point me to the problem.
I got the below code which shows marquee text - scrolling text. Works fine on all platforms except iphones. Any idea what's causing the issue?
On iphones it seems to be empty, but then all of a sudden itll show really fast scrolling text, then nothing again
.marquee {
margin: auto;
margin-top: auto;
padding-bottom: 32px;
margin-top: 55px;
}
.marquee-wrapper {
position: relative;
overflow: hidden;
height: 40px;
display: flex;
justify-content: center;
}
.marquee-words {
margin: 0 auto;
white-space: nowrap;
overflow: hidden;
position: absolute;
z-index: 1;
}
.marquee-words span {
display: inline-block;
padding-left: 100%;
animation: marquee-keywords 30s linear infinite;
-webkit-animation: marquee-keywords 30s linear infinite;
font-size: 20px;
letter-spacing: 0.2em;
animation-delay: -14s;
-webkit-animation-delay: -14s;
}
.marquee-double span {
animation-delay: 1s;
-webkit-animation-delay: 1s;
}
#keyframes marquee-keywords {
0% {
transform: translate(0, 0);
}
100% {
transform: translate(-100%, 0);
}
}
#-webkit-keyframes marquee-keywords {
0% {
-webkit-transform: translate(0, 0);
}
100% {
-webkit-transform: translate(-100%, 0);
}
}
<div class="marquee">
<div class="marquee-wrapper">
<p class="marquee-words">
<span>One example and in front of the room, One example and in front of the room</span>
</p>
<p class="marquee-words marquee-double">
<span>One example and in front of the room, One example and in front of the room</span>
</p>
</div>
</div>
I did not pin down exactly why IOS might be getting confused, but it may be some combination of flex and animation delays because if all this stripped away the problem disappears.
As you already have two copies of the complete text, this snippet simply puts them altogether in one element and animates that element but moving it just 50% of its width then starting again.
That way the start of the text goes directly into the position of the start of the second copy so the changeover is visually seamless.
.container {
overflow: hidden;
}
.marquee {
margin: 0;
padding-bottom: 32px;
margin-top: 55px;
display: inline-block;
}
.marquee-words {
white-space: nowrap;
animation: marquee-keywords 15s linear infinite;
font-size: 20px;
letter-spacing: 0.2em;
}
#keyframes marquee-keywords {
0% {
transform: translateX(0%);
}
100% {
transform: translateX(-50%);
}
}
<div class="container">
<div class="marquee">
<div class="marquee-words">One example and in front of the room, One example and in front of the room, One example and in front of the room, One example and in front of the room, </div>
</div>
</div>
Note: although the text is styled not to wrap it seems that a trailing space causes a slight mis-alignment of the text (a very slight jerkiness) when it is repeating at 50%. The final trailing space is replaced with a non breaking space in the snippet so that this space does not get ignored.
I am trying to have a marquee that appears to be infinite looping while I have the css that makes this look good on desktop when on mobile or adjusting the window the spacing becomes jumbled and some elements disappear.
I have used the css I found here How to create a marquee that appears infinite using CSS or Javascript and this a codepen of what I have so far. https://codepen.io/zjolley/pen/gOWXqee
<div class="bannerone">
<span>Dragon</span>
<span>Element</span>
<span>Charger</span>
<span>ZipDrive</span>
<span>LightHouse</span>
<span>Exxtra</span>
<span>Hub</span> <span>iOS15</span>
<span>File Drive</span>
<span>Netherverse</span>
<span>CLpool</span>
</div>
<div class="bannertwo">
<span>Dragon</span>
<span>Element</span>
<span>Charger</span>
<span>ZipDrive</span>
<span>LightHouse</span>
<span>Exxtra</span>
<span>Hub</span> <span>iOS15</span>
<span>File Drive</span>
<span>Netherverse</span>
<span>CLpool</span>
</div>
<div class="bannerthree">
<span>Dragon</span>
<span>Element</span>
<span>Charger</span>
<span>ZipDrive</span>
<span>LightHouse</span>
<span>Exxtra</span>
<span>Hub</span> <span>iOS15</span>
<span>File Drive</span>
<span>Netherverse</span>
<span>CLpool</span>
</div>
<div class="bannerfour">
<span>Dragon</span>
<span>Element</span>
<span>Charger</span>
<span>ZipDrive</span>
<span>LightHouse</span>
<span>Exxtra</span>
<span>Hub</span> <span>iOS15</span>
<span>File Drive</span>
<span>Netherverse</span>
<span>CLpool</span>
</div>
</div>
//CSS CODE
.banner {
height: 40px;
position: relative;
overflow: hidden;
font-family: Roobert;
font-style: normal;
font-weight: normal;
font-size: 24px;
line-height: 36px;
width: 100%;
}
.banner .bannerone {
animation: bannermove 40s linear infinite;
}
.banner .bannertwo {
animation: bannermove 40s linear 10s infinite;
}
.banner .bannerthree {
animation: bannermove 40s linear 20s infinite;
}
.banner .bannerfour {
animation: bannermove 40s linear 30s infinite;
}
.banner div {
position: absolute;
width: 100%;
right: 100%;
height: 40px;
display: flex;
justify-content: space-between;
}
.banner:hover div {
animation-play-state: paused;
}
#keyframes bannermove {
0% {
right: 100%;
}
50% {
right: -100%;
}
100% {
right: -100%;
}
} ```
You are on the right track having more than one copy of the texts.
But you can simplify things - think of all the text stretched out in a line in just one banner. You have an even number of copies, so if you translate the whole banner to the left (negative X direction) by 50% on each iteration of the animation then start back again, where second half had got to (x=0) will be overwritten by the first half and it will all appear continuous.
You can probably get away with just two copies, it depends on how spread out you want things to be on really wide screens, but I've left the 4 copies in there just in case you need them.
.banner {
height: 40px;
position: relative;
overflow: hidden;
font-family: Roobert;
font-style: normal;
font-weight: normal;
font-size: 24px;
line-height: 36px;
min-width: 200vw;
/* ADDED */
animation: bannermove 40s linear infinite;
display: flex;
justify-content: space-between;
}
.banner:hover {
animation-play-state: paused;
}
#keyframes bannermove {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-50%);
}
}
.banner div {
padding: 10px;
/* just to ensure there is space between even on small devices */
}
<div class="banner">
<div>Dragon</div>
<div>Element</div>
<div>Charger</div>
<div>ZipDrive</div>
<div>LightHouse</div>
<div>Exxtra</div>
<div>Hub</div>
<div>iOS15</div>
<div>File Drive</div>
<div>Netherverse</div>
<div>CLpool</div>
<div>Dragon</div>
<div>Element</div>
<div>Charger</div>
<div>ZipDrive</div>
<div>LightHouse</div>
<div>Exxtra</div>
<div>Hub</div>
<div>iOS15</div>
<div>File Drive</div>
<div>Netherverse</div>
<div>CLpool</div>
<div>Dragon</div>
<div>Element</div>
<div>Charger</div>
<div>ZipDrive</div>
<div>LightHouse</div>
<div>Exxtra</div>
<div>Hub</div>
<div>iOS15</div>
<div>File Drive</div>
<div>Netherverse</div>
<div>CLpool</div>
<div>Dragon</div>
<div>Element</div>
<div>Charger</div>
<div>ZipDrive</div>
<div>LightHouse</div>
<div>Exxtra</div>
<div>Hub</div>
<div>iOS15</div>
<div>File Drive</div>
<div>Netherverse</div>
<div>CLpool</div>
</div>
Obviously you'll want to adjust the timing to suit you purposes.
I am trying to recreate Tom Riddle's text animation from Harry Potter chambers of secrets (as seen on here). I currently am still trying to use css in simulating it as can be done on Adobe Ae (as seen on here). Currently, what I have done is using keyframes to simulate the fade in a loop. I have no idea on how to move forward in this process. Here is my current code:
body{
background-color: bisque;
font-family: 'Times New Roman', Times, serif;
font-weight: bold;
font-size: 100px;
}
.center {
position: absolute;
width: 550px;
height: 250px;
top: 50%;
left: 50%;
margin-left: -250px;
margin-top: -150px;
}
.tr-fade{
opacity: 0;
transition: opacity 1s ease;
animation-duration: 6s;
animation-name: tr-fade-animation;
animation-delay: 0;
animation-iteration-count: infinite;
animation-direction: forward;
}
#keyframes tr-fade-animation {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="text-container">
<div class="center tr-fade">
Hi, This is Tom Riddle.
</div>
</div>
</body>
</html>
I have researched about fractal noises in css, however none seemed to use image masking for text transition effects. What approach should I use in order to get the desired effect (SVG animation maybe)? Any help on this?
I am currently working on a game and I need some help with some html and css.
I have a page called "crime" and there it is 6 possible crimes you can take, on each of them I want to have a progress bar that counts down. I have made it work on the first one, but as I see on the code the keyframes doesnt go to a specific div, but everything that have the "fill" animation.
Since the crimes have different cooldown times I need to have them show another progress then the others.
<div class="bar">
<div class="in"></div>
</div>
.bar {
border: 1px solid #666;
height: 20px;
width: 100%;
}
.in {
animation: fill 20s linear 1;
height: 100%;
background-color: pink;
}
#keyframes fill {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
I think you need to post more code to make us understand precisely what you are doing.
From what you explained so far, I think you just need to create more keyframes and assigned them to the crime you want.
So if you have this for every crime div
<div class="bar">
<div class="in"></div>
</div>
then you could change the name of the inner div for each crime. E.g:
<div class="bar">
<div class="in-1"></div> //bar for crime 1
</div>
<div class="bar">
<div class="in-2"></div> //bar for crime 2
</div>
.in-1 {
animation: fill1 20s linear 1;
height: 100%;
background-color: pink;
}
.in-2 {
animation: fill2 20s linear 1;
height: 100%;
background-color: pink;
}
#keyframes fill1 {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
#keyframes fill2 {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
and so on for all the crimes.
Hope that helped :)
I am new to this and I'm stuck on a project.
I am trying to get an animation to cause an image to appear on the page when you hover over another element.
I already have the animation working, but what I can't figure out is how first to make the image invisible and the cause the animation to start when the said element is hovered in this case a h4 element.
I've tried everything I can think of and read several other posts relating to this but no luck. I think it might be something with me having to add position (absolute or relative) but I'm not sure.
This is the css for that section without any hovering function:
.timeline-img {
visibility: hidden;
}
.hovered:hover + p + .timeline-img {
animation: 7s alternate slideIn;
transition: all .2s;
visibility: visible;
}
.hovered:hover:after + p + .timeline-img {
visibility: visible;
}
#keyframes slideIn {
from {
margin-left: 100%;
width: 300%;
opacity: 0;
}
to {
margin-left: 0%;
width: 100%;
opacity: 1;
}
}
<div class="content">
<h4 class="hovered">Shepherds discovered coffee in Ethiopia circa 800 A.D.</h4>
<p>Legend has it that 9th century goat herders noticed the effect caffeine had on their goats, who appeared to "dance" after eating coffee berries. A local monk then made a drink with coffee berries and found that it kept him awake at night, thus the original cup of coffee was born.</p>
<div class="timeline-img">
<img src="shepherd.jpg" alt="Shepherd" class="fact-img">
</div>
</div>
Thanks to whoever helps me out and please explain as I'm still very new to this and learning.
You can do something like this:
The syntax is straightforward enough: just two or more selectors separated by a plus (+) symbol. The simplest construction is two elements with a plus between them. read more: Adjacent-Sibling Selector
.content h4:hover + p + .timeline-img{
animation: 7s alternate slideIn;
transition: all .2s;
}
#keyframes slideIn {
from {
margin-left: 100%;
width: 300%;
opacity: 0;
}
to {
margin-left: 0%;
width: 100%;
opacity: 1;
}
}
<div class="content">
<h4 class="hovered">Shepherds discovered coffee in Ethiopia circa 800 A.D.</h4>
<p>Legend has it that 9th century goat herders noticed the effect caffeine had on their goats, who appeared to "dance" after eating coffee berries. A local monk then made a drink with coffee berries and found that it kept him awake at night, thus the original cup of coffee was born.</p>
<div class="timeline-img">
<img src="shepherd.jpg" alt="Shepherd" class="fact-img">
</div>
</div>
In this example,
We set a :hover pseudo-class on the target sibling (~) class.
i.e. .hovered:hover ~ .timeline-img
We then use the animation-play-state property on the standard + hover state items.
animation-play-state: paused
animation-play-state: running
https://developer.mozilla.org/en-US/docs/Web/CSS/animation-play-state
.timeline-img {
-webkit-transition: all .2s;
-o-transition: all .2s;
transition: all .2s;
/* necessary */
-webkit-animation: 2s alternate slideIn;
animation: 2s alternate slideIn;
-webkit-animation-play-state: paused;
animation-play-state: paused;
/* Optional */
-webkit-animation-iteration-count: 2;
animation-iteration-count: 2;
-webkit-animation-direction: alternate;
animation-direction: alternate;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.hovered:hover ~ .timeline-img {
-webkit-animation-play-state: running;
animation-play-state: running;
}
#-webkit-keyframes slideIn {
from {
margin-left: 100%;
width: 300%;
opacity: 0;
}
to {
margin-left: 0%;
width: 100%;
opacity: 1;
}
}
#keyframes slideIn {
from {
margin-left: 100%;
width: 300%;
opacity: 0;
}
to {
margin-left: 0%;
width: 100%;
opacity: 1;
}
}
.red {
background: red;
height: 50px;
width: 50px;
border-radius: 100%
}
<div class="content">
<h4 class="hovered">Shepherds discovered coffee in Ethiopia circa 800 A.D.
</h4>
<p>
Legend has it that 9th century goat herders noticed the effect caffeine had on their goats, who appeared to "dance" after eating coffee berries. A local monk then made a drink with coffee berries and found that it kept him awake at night.
</p>
<div class="timeline-img">
<div class="red"></div>
</div>
</div>
Try this once.
.timeline-img{
transition: all .2s;
animation: 7s alternate slideIn;
animation-play-state: paused;
}
.hovered:hover ~ .timeline-img{
animation-play-state:running;
}
#keyframes slideIn {
from {
margin-left: 100%;
width: 300%;
opacity: 0;
}
to {
margin-left: 0%;
width: 100%;
opacity: 1;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content">
<h4 class="hovered">Shepherds discovered coffee in Ethiopia circa 800 A.D.</h4>
<p>Legend has it that 9th century goat herders noticed the effect caffeine had on their goats, who appeared to "dance" after eating coffee berries. A local monk then made a drink with coffee berries and found that it kept him awake at night, thus the original cup of coffee was born.</p>
<div class='timeline-img'>
<img src="shepherd.jpg" alt="Shepherd" class="fact-img">
</div>
</div>