Creating Smooth Marquee Animations with CSS

Aug 2, 2024

Notes on Marquee Animation with CSS

Introduction

  • Discussion on marquee animation, associated with age (deprecated marquee element).
  • Focus on recreating marquee animations using CSS.
  • Trend of using marquee elements in websites.
  • Video split into two parts: 1. Text marquee 2. Logo marquee.

Part 1: Text Marquee

  • Starting Point: Old-school marquee element still functioning but deprecated.
  • Creating a New Marquee:
    • Add a new <div> for text.
    • Implement basic CSS styles (padding, text color, font size).

CSS Implementation Steps

  1. Class Naming: Add marquee-text class to marquee div.
  2. CSS Styles for Paragraphs:
    • Add border, border-radius, padding.
  3. Flexbox Layout:
    • Set display: flex; to align texts in a single line.
    • Add gap property (4.8 rem) for spacing.
  4. Prevent Scroll Bar:
    • Wrap marquee elements in another <div> called MarqueeTextTrack.
    • Set overflow to hidden.

Keyframe Animation

  • Creating Animation:
    • Define keyframes marquee-move-text to translate X by -100%.
    • Apply animation to MarqueeTextTrack:
      • animation: marquee-move-text 10s linear infinite;
  • Issue: Large gap and jumping effect when animation restarts.

Solution to Jumping Effect

  • Duplicate Marquee Elements:
    • Duplicate texts to ensure smooth transition.
  • Width Adjustment:
    • Set width of MarqueeTextTrack to max-content.
  • Animation Play State:
    • Move with transform: translateX(-50%); for seamless looping.

Additional Adjustments

  • Margins and Padding:
    • Address gaps caused by flexbox gap property by adding padding-left: 4.8rem;.
  • Ensure that duplicated content has aria-hidden=true for accessibility.
  • Ensure an even amount of duplicated text for proper flipping.

Enhancements

  • Fade Out Effect:
    • Create class fade-out-horizontal with linear gradient mask for a fade effect at the edges.
  • Animation Direction:
    • Ability to reverse marquee direction using animation-direction: reverse;.
  • Configure Speed with CSS Variables:
    • Use var(speed, 10s) to adjust speed dynamically.

Final Touches

  • Rotation Effect:
    • Create classes for rotating marquee elements left and right.
  • Visual Appearance:
    • Background color for marquee elements.
  • Conclusion:
    • Code will be available in the description; subscribe for next video on logo slider with seamless animation.

Summary

  • Practical implementation of marquee animations with CSS.
  • Importance of accessibility and aesthetic value in design.
  • Upcoming video focused on logo marquee.