7

I need to create two marquees (one with a repeating image and one with repeating links) that span the browser window, whatever size that may be; the marquee items need to be initially displayed at the left side of the screen and not take a few seconds to travel across to appear. Each of them need to be about 20px/30px apart. The marquee needs to appear infinite; that is, items need to fill up the entire width of the window at all times. The marquee needs to pause on hover.

I've carved out the basics of what I'm essentially looking to do using CSS. With the help of this response https://stackoverflow.com/a/56524853/11623961, I was able to get the pause on hover I was looking for.

Unfortunately, I'm still left unsure of how to make the animation appear without gaps and as if there's an infinite amount of words traveling from the right to the left. I'm trying to achieve a marquee like the one at the top of this site https://www.at-elier.org/, but with CSS, if possible or minimal Javascript, if necessary.

body { 
  margin: 0;
  font-family: "UniversLTPro-Ex";
  font-size: 30px;
}

a {
    text-decoration: none;
    color: #000;
}

.marquee {
  height: 35px;
  width: 100%;

  overflow: hidden;
  position: relative;
  background-color: #e9e5fb;  
  border-top: 1px solid black;
  border-bottom: 1px solid black;
  padding: 8px 0 4px 0;
}

.marquee div {
  display: inline-block;
  width: 300%;
  height: 40px;

  position: absolute;
  overflow: hidden;

  animation: marquee 30s linear infinite;
}

.marquee span {
  float: left;
  width: 1100px;
}

.marquee:hover div {
  animation-play-state: paused;
}

@keyframes marquee {
  0% { left: 0%; }
  100% { left: -1100px; }
}

/* @import must be at top of file, otherwise CSS will not work */
@import url("//hello.myfonts.net/count/3909a7");

  
@font-face {font-family: 'UniversLTPro-Ex';src: url('webfonts/3909A7_0_0.eot');src: url('webfonts/3909A7_0_0.eot?#iefix') format('embedded-opentype'),url('webfonts/3909A7_0_0.woff2') format('woff2'),url('webfonts/3909A7_0_0.woff') format('woff'),url('webfonts/3909A7_0_0.ttf') format('truetype');}
 
<div class="marquee">
  <div>
    <span><a href="#">twitter</a>&nbsp;&nbsp;&nbsp;
                <a href="#">instagram</a>&nbsp;&nbsp;&nbsp; 
                <a href="#">pinterest</a>&nbsp;&nbsp;&nbsp;
                <a href="#">spotify</a>&nbsp;&nbsp;&nbsp; 
               <a href="#">magazine</a>&nbsp;&nbsp;&nbsp;</span>
    <span><a href="#">twitter</a>&nbsp;&nbsp;&nbsp;
                <a href="#">instagram</a>&nbsp;&nbsp;&nbsp; 
                <a href="#">pinterest</a>&nbsp;&nbsp;&nbsp;
                <a href="#">spotify</a>&nbsp;&nbsp;&nbsp; 
               <a href="#">magazine</a>&nbsp;&nbsp;&nbsp;</span>
  </div>
</div>
lucygoosey
  • 127
  • 1
  • 2
  • 9
  • 1
    You would need to use javascript to achieve this. It involves cloning the text once it has traveled maybe half it's width. Then do a clone of the clone once that has traveled half of it's width and remove the original text to prevent loads of elements being created. Then rinse and repeat. – WizardCoder Jun 17 '19 at 23:01
  • 2
    @LawrenceCherone while a solid throwback it is ill advisable to use the element as most browsers no longer support it. (but it still may work via some polyfills) – Michael Sorensen Jun 17 '19 at 23:06
  • @WizardCoder thanks so much! To be honest, I both anticipated and feared this answer. I noticed a similar idea on a different site, but I hoped for a solution with CSS. I'm very new to Javascript so I'm not quite sure how to get there. – lucygoosey Jun 17 '19 at 23:11
  • 1
    @lucygoosey It is a bit tricky if you are new to javascript. If you google "Text Scrolling Plugin for jQuery - Marquee", the first result is for a plugin I have used before, which will allow you do what you need. It might be a bit old now though, so have a look around for alternatives. – WizardCoder Jun 17 '19 at 23:19
  • @WizardCoder That's amazing! I will definitely have a look around for other options of a similar nature. Thanks again for your help and for not being condescending while at it! All the best. – lucygoosey Jun 17 '19 at 23:37
  • @lucygoosey [Marquee CSS/JavaScript](https://stackoverflow.com/a/55429324/2813224), [Marquee CSS](https://stackoverflow.com/a/53840508/2813224), [Vertical Marquee CSS](https://stackoverflow.com/a/54821785/2813224) – zer00ne Jun 17 '19 at 23:49

1 Answers1

6

You are so close. Hopefully the demo below is self explainable but, basically you need to start your key frames at -100% your marquee's width then end at 100% so it's off screen before it restarts.

Hope this helps!

[edit] added continuous scrolling

body { 
  margin: 0;
  font-family: "UniversLTPro-Ex";
  font-size: 30px;
}

a {
    text-decoration: none;
    color: #000;
}

.marquee {
  height: 35px;
  width: 100%;

  overflow: hidden;
  position: relative;
  background-color: #e9e5fb;  
  border-top: 1px solid black;
  border-bottom: 1px solid black;
  padding: 8px 0 4px 0;
}


/* would need to be adjusted depending on time */
.marquee .marqueeone{
  animation: marquee 10s linear infinite
}

.marquee .marqueetwo{
  animation: marquee 10s linear 2.5s infinite 
}

.marquee .marqueethree{
  animation: marquee 10s linear 5s infinite
}

.marquee .marqueefour{
  animation: marquee 10s linear 7.5s infinite
}

/* even out the elements */
.marquee div {
  position: absolute;
  width: 100%;
  left: 100%;
  height: 40px;
  display: flex;
  justify-content: space-between;
}

.marquee:hover div {
  animation-play-state: paused;
}

/* add delay at the end of animation so you dont start while another div is going */
@keyframes marquee {
  0% { left: 100%; }
  50% { left: -100%; }
  100% {left: -100%}
}

/* @import must be at top of file, otherwise CSS will not work */
@import url("//hello.myfonts.net/count/3909a7");

  
@font-face {font-family: 'UniversLTPro-Ex';src: url('webfonts/3909A7_0_0.eot');src: url('webfonts/3909A7_0_0.eot?#iefix') format('embedded-opentype'),url('webfonts/3909A7_0_0.woff2') format('woff2'),url('webfonts/3909A7_0_0.woff') format('woff'),url('webfonts/3909A7_0_0.ttf') format('truetype');}
<div class="marquee">
    <div class="marqueeone"><a href="#">twitter</a>&nbsp;&nbsp;&nbsp;
                <a href="#">instagram</a>&nbsp;&nbsp;&nbsp; 
                <a href="#">pinterest</a>&nbsp;&nbsp;&nbsp;
                <a href="#">spotify</a>&nbsp;&nbsp;&nbsp; 
               <a href="#">magazine</a>&nbsp;&nbsp;&nbsp;
               </div>
    <div class="marqueetwo"><a href="#">twitter</a>&nbsp;&nbsp;&nbsp;
                <a href="#">instagram</a>&nbsp;&nbsp;&nbsp; 
                <a href="#">pinterest</a>&nbsp;&nbsp;&nbsp;
                <a href="#">spotify</a>&nbsp;&nbsp;&nbsp; 
               <a href="#">magazine</a>&nbsp;&nbsp;&nbsp;</div>
         <div class="marqueethree"><a href="#">twitter</a>&nbsp;&nbsp;&nbsp;
                <a href="#">instagram</a>&nbsp;&nbsp;&nbsp; 
                <a href="#">pinterest</a>&nbsp;&nbsp;&nbsp;
                <a href="#">spotify</a>&nbsp;&nbsp;&nbsp; 
               <a href="#">magazine</a>&nbsp;&nbsp;&nbsp;</div>
                   <div class="marqueefour"><a href="#">twitter</a>&nbsp;&nbsp;&nbsp;
                <a href="#">instagram</a>&nbsp;&nbsp;&nbsp; 
                <a href="#">pinterest</a>&nbsp;&nbsp;&nbsp;
                <a href="#">spotify</a>&nbsp;&nbsp;&nbsp; 
               <a href="#">magazine</a>&nbsp;&nbsp;&nbsp;
      </div>
</div>
Michael Sorensen
  • 1,850
  • 12
  • 20
  • ahh, that's hot. Although I think they wanted the text to always be visible. – WizardCoder Jun 17 '19 at 23:07
  • ah you're right. That's what I get for not reading the whole answer. I'll see if I can come up with another solution and edit it here – Michael Sorensen Jun 17 '19 at 23:11
  • Thanks, I really appreciate this! But unfortunately, @WizardCoder is correct. I am looking for the text to always be visible. – lucygoosey Jun 17 '19 at 23:13
  • @lucygoosey took a lot finaggling but, I did come up with a solution if you want to check out my edit. You may need to break out a calculator or use the `calc` css attribute to make the animation slower. – Michael Sorensen Jun 17 '19 at 23:43
  • @MichaelSorensen wow! This is SO helpful! Thanks for spending the time to create this for me! I am still left with one question (if you have the time to answer it): how would I go about adjusting this to smaller breakpoints? It works at nearly all of my breakpoints, but not when I hit the mobile/small tablet sizes. For example, if you view this at 480px, you get overlap. Would I remove the marquees to get a lesser width (let's say I remove .marqueefour and .marqueethree) and then adjust the delay or is it all in the timing of the existing divs, regardless of their widths? – lucygoosey Jun 18 '19 at 00:23
  • No problem! And, yeah the number of marquee's only had to do with the timing. I think you can do it with just 2 but, I couldn't quite figure it out. Anyways, for the breakpoints I would suggest just adding some media queries and reducing the font-size with this solution. This is not ideal but, any further I would suggest using one of the plugins suggested on the OP. Good luck! – Michael Sorensen Jun 18 '19 at 04:29
  • @MichaelSorensen wonderful! Thank you again for all your help! – lucygoosey Jun 18 '19 at 15:27