Scrolling Text Loop with CSS Animation

I am currently working on creating a unique CSS animation that resembles a looped conveyor belt. Essentially, I want the text within a div to disappear off the screen to the right and then reappear from the left.

Here's the approach I've taken so far in an attempt to replicate this effect.

.marquee-section {
    position: relative;
    min-height: 82px;
}

.marquee-section, .marquee-section * {
    overflow: hidden;
}

.marquee {
    white-space: nowrap;
}

.marquee-div {
    position: absolute;
    left: -100%;
    animation: move linear 12.5s infinite;
    min-width: 100%;
}

@keyframes move {
    from { left: -100%; }
    to { left: 100%; }
<div class="marquee-section">
    <div class="marquee-div">
        <div class="marquee">START &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; END</div>
    </div>
</div>

However, I have encountered a challenge where the text only starts from the left again once it completely disappears offscreen to the right. This results in empty space both before and after the text as it moves towards the right.

My goal is to eliminate any white space and instead have text on both the left and right sides of the starting and ending points of the animation. This is a feature commonly seen in Webflow, and you can view an example here.

Is it possible to achieve this using CSS alone? Or are there any frameworks that can facilitate this type of animation?

Any suggestions or guidance on how to achieve this would be greatly appreciated.

Answer №1

For a different approach, consider updating the translateX value instead of the left value.

To eliminate white space before and after the text, I have replicated the text and then utilized transform: translateX(-50%) in the keyframes. Please take a look at the demo.

.marquee-section {
    position: relative;
    min-height: 82px;
}

.marquee-section, .marquee-section * {
    overflow: hidden;
}

.marquee {
    white-space: nowrap;
}

.marquee-div {
    position: absolute;
    animation: move-left-to-right linear 12.5s infinite;
}

/* utilize this keyframe to move in the left to right direction */
@keyframes move-left-to-right {
    from {
        transform: translateX(-50%);
    }
    to {
        transform: translateX(0);
    }
}

/* utilize this keyframe to move in the right to left direction */
@keyframes move-right-to-left {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-50%);
    }
}
<div class="marquee-section">
    <div class="marquee-div">
        <div class="marquee">START &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; END &bull;
START &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; MID &bull; END &bull;</div>
    </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Preventing Banner Images from Covering Side Carts in E-commerce Stories - Tips and Tricks

I'm encountering an issue with the side cart and suspect that my CSS is to blame. Can you assist me in resolving this problem? The webpage has a background image—a full-width banner. However, when I open the side cart, the image overlaps it, concea ...

"Switching a div's visibility when a link is clicked

http://jsfiddle.net/FsCHJ/2/ Currently, when I add another link, it automatically uses the same functionality as the toggle button. What I want is for "Toggle Edit Mode" to toggle a hidden div on and off. I attempted to modify the code from $("a").click(f ...

Personalizing the share button by changing the icon font to an image

I've been working on incorporating this share button into my website.... Although it functions properly as is, I want to switch out the icon font for an image. I attempted to modify certain CSS properties, but encountered some issues. http://jsfidd ...

Can you make two columns in CSS that are left floated and maintain their original order?

While the title may not provide much clarity, I am struggling to put into words exactly what I am trying to achieve. I have created a layout in Photoshop which I have shared below to help illustrate my goal. Essentially, I have a blog that displays my sto ...

Issue with Bootstrap 4 navbar functionality on smaller screens

I'm currently in the process of integrating a navbar that transforms the navbar choices into a dropdown menu on smaller screens (as illustrated in the documentation available here). However, I am encountering an issue where the button responsible for ...

angularjs: container holding directive is currently not visible, with a height and width of 0 pixels

When implementing a directive in this way, the actual element (<a-directive>) appears to have dimensions of 0px height and 0px width. View jsfiddle example var myApp = angular.module('myApp', []).directive('aDirective', function ...

The luminosity of MeshBasicMaterial in Three.js

In my current setup with threejs, I am utilizing MeshBasicMaterial for lighting effects. Each element contains a simulated point light within. I have assigned a variable named color, defined as rgb(random value, random value, random value). I am looking ...

Tips on creating a slow and gradual border animation that unfolds smoothly

I am looking to create an animation effect on a border, gradually revealing it like in this Codepen example. However, my specific requirements are: The previous line should not be removed, but rather shown along with the new border. The border color ...

PHP file secured to only accept variables posted from HTML form

This is a basic HTML/AJAX/PHP script I have implemented. <form id="new_user" action="" method="post"> <div class="col-md-3 form-group"> <label for="username">Username</label> <input type="text" class="form-control" name ...

Creating responsive layouts with flexible image sizes using Flexbox

My exploration of Flexbox began by testing it on an existing template sourced from a previous stackoverflow question. I am currently focusing on adjusting the image size to better fit within its parent div. max-width: 50px; height: auto; margin:auto; ...

What is the best way to create a new variable depending on the status of a button being disabled or enabled

Imagine a scenario where a button toggles between being disabled when the condition is false (opacity: 0.3) and enabled when the condition is true (opacity: 1). Let's set aside the actual condition for now -- what if I want to determine when the butt ...

Ways to position loading animation in the center and create a lightbox effect for the rest of the page

I have implemented a custom loader in CSS with the following styles: .loader { border: 16px solid #f3f3f3; /* Light grey */ border-top: 16px solid #3498db; /* Blue */ border-radius: 50%; width: 80px; height: 80px; animation: spin 2s linear inf ...

Error message: Unable to access .exe file through HTML link

We have a need to include an HTML link on our intranet site that, when clicked, will open an .exe file that is already installed on all user machines. I attempted the following code: <a href = "C:\Program Files\Cisco Systems\VPN&bsol ...

Conceal and Reveal Navigation Bar

On a mobile screen, here is how my navigation bar looks: Just to clarify, I am currently only focusing on making the nav bar responsive and not other content. The stylus code for the navigation bar is as follows: -> code in stylus!!! .nav display ...

The clip-path in Div: Css is malfunctioning and not displaying correctly

I am trying to create a chat bubble using CSS with rounded corners and a bottom-right arrow. However, I am having trouble getting the arrow to display correctly. https://i.stack.imgur.com/gVXOV.png The CSS styling for the chat bubble is as follows: ...

Conceal HTML elements from the bottom as new content is being added dynamically

I am currently working on a comments feed feature. By default, only the first four comments are displayed, with an option to show more when clicking the "show more" anchor. The issue I'm facing is that if new comments are dynamically added, the CSS hi ...

Is there a way to synchronize the autohide duration for both the LinearProgress MUI and SnackBar components?

Can someone help me align my SnackBar with the LinearProgress so that they both have an auto-hide duration of 4 seconds? I've been struggling to figure it out for hours and haven't found a solution yet. Could the issue be in the useEffect part of ...

Showing text instantly upon clicking a radio button, in real-time

I'm working with a set of radio buttons that are linked to numbers ranging from 1 to 24. I need to show the selected number in another part of the page when a radio button is clicked. What would be the best way to achieve this? ...

How can I stop and hover over time in AngularJs Interval?

Within my UI, I have a time element that is continuously updated using AngularJS Interval. Even the milliseconds are constantly running. Is it possible to implement a feature where the time pauses when hovering over it? Any assistance would be greatly appr ...

Bootstrap scrollspy feature experiencing malfunction

I am encountering an issue with scrollspy on Bootstrap version 5.1. Despite following the examples in the documentation (links provided below), I am unable to make it work; there are no visible changes when scrolling. My goal is for the corresponding link ...