Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
a Summer night - @916.15
Activity rating: Four Stars Posts & Arts: 69/1k.beats Random | Recent Posts | Guild Recents
News: :happy: Open the all windows! Your mind needs storms and air! :happy: Guild Events: Summerween Watch-a-thon

+  MelonLand Forum
|-+  Materials & Info
| |-+  ♺ ∙ Web Crafting Materials
| | |-+  How to make a marquee that pauses when you hover it


« previous next »
Pages: [1] Print Embed
Author Topic: How to make a marquee that pauses when you hover it  (Read 71 times)
Noah_S
Sr. Member ⚓︎
****
View Profile WWWArt


Noah. Earth. I make website. I.. I.. Noah. Earth.
⛺︎ My Room
iMood: Noah_S
RSS: RSS

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!I got robbed by Dan Q on Melonland!I met Dan Q on Melonland!A coin!EnbyAce
« on: a Summer day » Embed

I was reading the websites pet peeves thread, and saw some discussion about marquees. So here's a code for making them pause when you hover over them.

Code
<style>
.scroll-text {
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  animation: scroll-left 15s linear infinite;
  &:hover {
  animation-play-state: paused;
}
}

@keyframes scroll-left {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(-100%);
  }
}
</style>

<div class="scroll-text">This scrolls left using CSS</div>

I tested it in the w3schools tryit editor to check, and it works.

Code
  animation: scroll-left 15s linear infinite;

This affects how fast it's moving. Lower numbers make faster movement.

I don't fully understand the code myself, I haven't played with animations and this is a frankencode from different sources that I jigsawed until I found a combination that worked. But one of the sources said that this wouldn't confuse screenreaders, which <marquee> does, and I hope that that's accurate.

Logged

perfectionist_better.gifweb_designer.gifspeed_of_time.gifbutton290.pngmy_dream_wedding.gifClippy beats AI

Artifact Swap: IT'S THE FINAL COUNTDOWNPaw printThe Worm is creeping around Melonland profiles!Large watercraftGrowing ballLucky!Melonland has encountered a bugMerry ChristmasMessage BuddyMelon bite
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #1 on: a Summer day » Embed

I don't fully understand the code myself, I haven't played with animations and this is a frankencode from different sources that I jigsawed until I found a combination that worked.

Let me see if I can help with the comprehension! I've added some comments and tweaked the indentation.

Code
<style>
/* Anything with <... class="scroll-text">: */
.scroll-text {
  /* 1. Is as wide as whatever contains it: */
  width: 100%;
  /* 2. Anything that doesn't fit within it gets hidden: */
  overflow: hidden;
  /* 3. And text isn't allowed to wrap within it (therefore anything that "goes off the side" is hidden!): */
  white-space: nowrap;
  /* 4. Also, it gets an animation called "scroll-left", which
   *    takes 15 seconds to run (15s)
   *    at the same speed for the entire process (linear)
   *    repeating forever (infinite)
   */
  animation: scroll-left 15s linear infinite;

  /* When the cursor hovers over that <... class="scroll-text">... */
  &:hover {
    /* ...the animation is paused. */
    animation-play-state: paused;
  }
}

/* This bit defines the animation called "scroll-left": */
@keyframes scroll-left {
  /* 1. The animation STARTS with... */
  from {
    /* ...the position of the contents moved 100% of its width, to the right (X), i.e. entirely "off" the right. */
    transform: translateX(100%);
  }
  /* 2. The animation ENDS with... */
  to {
    /* ...the position of the contents moved 100% of its width, to the left (minus X), i.e. entirely "off" the left. */
    transform: translateX(-100%);
  }
}
</style>

<!--
  here's an element that scrolls, because it has class="scroll-text"
  so everything above applies. It doesn't have to be a <div>; indeed
  a <p>, <h2> or <li> might be more-applicable depending on the
  circumstances!
-->
<div class="scroll-text">This scrolls left using CSS</div>

With all of that new knowledge, we now have everything we need to e.g.

- make the animation faster or slower (by changing "15s" to some other duration)
- make the marquee "bounce" backwards and forwards by adding animation-direction: alternate;
- delay the start of the marquee with animation-delay: 2s; (2 second delay), OR have it start "as if" it had been playing a while already with a negative value like animation-delay: -2s; (normal loop, but when the page loads it's like it started two seconds ago
- swap the "linear" to make it gradually speed up at the start (ease-in), gradually slow down at the end (ease-out), or both (ease-in-out) - these look a little odd for text marquees, but are useful in some other animations
- make it run "backwards" with animation-direction: reverse; (or by swapping the from { ... } and to { ... } section contents

Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif

Artifact Swap: I met Dan Q on Melonland!PolyamorousDoctor RedactedJoined 2025!
Noah_S
Sr. Member ⚓︎
****
View Profile WWWArt


Noah. Earth. I make website. I.. I.. Noah. Earth.
⛺︎ My Room
iMood: Noah_S
RSS: RSS

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!I got robbed by Dan Q on Melonland!I met Dan Q on Melonland!A coin!EnbyAce
« Reply #2 on: a Summer day » Embed

Thank you. I think you cracked animations for me. I've been fascinated by that dragonfly in the garden.

Logged

perfectionist_better.gifweb_designer.gifspeed_of_time.gifbutton290.pngmy_dream_wedding.gifClippy beats AI

Artifact Swap: IT'S THE FINAL COUNTDOWNPaw printThe Worm is creeping around Melonland profiles!Large watercraftGrowing ballLucky!Melonland has encountered a bugMerry ChristmasMessage BuddyMelon bite
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 MelonLand Zap! Want to Login or Join ? Forum Art Hub Chat Webring Editor Recent Edits Tenement Arcade Web Guides Graphics Catalogue Wiki Newsletters Image Stream
Melon's Sites TamaNotchi Textures PixelSea GifyPet MoMG Ozwomp Online Loom Videos Leaky Webring Melonking
Tools Melon Software ArtHub Embed Maker ML Passports
Outlinks Webrings Internet Phone Book HTML Energy Declarations Hackers & Designers Frutiger Aero Forum m15o's Web Services 32Bit Cafe iMood
Minecraft: Online
Join: craft.melonking.net