Endless stream of text flowing in a continuous line within each paragraph

I am trying to create a unique scrolling effect for each line in a paragraph. The goal is to have each line repeat after one scroll is completed. For example:

Let's say there is a line like this in the paragraph:

1,2,3,4,

The desired outcome is for the 1 to come after the 4 once a single scroll has finished.

Although I have successfully implemented horizontal scrolling on the screen, I am struggling to make the sentences repeat.

Each sentence is wrapped in a span with either bar_content1 or bar_content2 classes to control the direction of movement.

I attempted to use the ::before function but couldn't get it to work as intended.

An image below illustrates the logic behind my ideal result.

Note: The HTML included in this question is not from my actual project, for privacy reasons. However, the code structure remains the same.

https://i.sstatic.net/hsJp4.png

.bar_content2 {
  display: block;
  width: 100%;
  transform: translateX(-100%);
  animation: move2 100s linear infinite;
}

@keyframes move2 {
  0% {
    transform: translateX(-100%);
  }
  50% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(-100%);
  }
}

.bar_content1 {
  display: block;
  width: 100%;
  transform: translateX(100%);
  animation: move1 100s linear infinite;
}

@keyframes move1 {
  0% {
    transform: translateX(100%);
  }
  50% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}


/* Animate each line in the paragraph */

p {
  overflow: hidden;
  position: relative;
  white-space: nowrap;
  /* Prevent line breaks */
}

p::before {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 100%;
  /* Start from the right side */
  animation: scrollText 20s linear infinite;
  /* Adjust the duration as needed */
}

@keyframes scrollText {
  0% {
    left: 100%;
  }
  100% {
    left: -100%;
  }
  /* Move to the left, creating the interlacing effect */
}
<p>
  <span class="bar_content1">1,2,3,4,</span>
  <span class="bar_content2"> 5,6,7,8, </span>
</p>

Answer №1

After reviewing your updates with the code and image illustrating the effect you desire, I now have a better understanding. It appears that you are looking for a carousel feature. A quick search online reveals numerous options available. I recommend checking out this page for some helpful resources: https://css-tricks.com/css-only-carousel/

I took the liberty of adapting the final example from that page, which utilizes a JS library called Flickity:

Although I have not personally utilized Flickety before, it appears to be quite promising based on my initial evaluation. It is straightforward to use, does not rely on additional dependencies, and should fulfill around 90% of your requirements!

Please note that Flickety offers various customization options, all of which can be explored here: . I have already set certain parameters in the data-flickity HTML attribute for you to adjust as needed.

.carousel {
  background: #EEE;
}

.carousel-cell {
  margin-right: 10px;
  width: 50%;
  background: #8C8;
  padding: 15px;
}
<link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css">
<script src="https://unpkg.com/flickity@2/dist/flickity.pkgd.min.js"></script>

<div class="carousel"
  data-flickity='{
    "autoPlay": 1500,
    "selectedAttraction": 0.01,
    "pauseAutoPlayOnHover": false,
    "friction": 0.15,
    "wrapAround": true,
    "draggable": false,
    "prevNextButtons": false,
    "pageDots": false,
    "contain": true
  }'>
  <div class="carousel-cell">1, 2, 3, 4</div>
  <div class="carousel-cell">5, 6, 7, 8</div>
  <div class="carousel-cell">9, 10, 11, 12</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

Displaying SQL data in a table using PHP

I've encountered a dilemma where the category name is being outputted as the same for both offered and wanted categories in PHP. This issue arises when trying to display categoryName differently for each type of category in a table. Despite attempting ...

Text overlay on Material UI Card

I am currently using the Material UI Card and CardMedia components in my application, but I am having trouble with overlaying text on top of the image. Below is a simplified version of what I have been attempting: <Card> <CardMedia image={this. ...

Concealed upper TD boundary in IE 8

I've been struggling all day to figure out this style issue without any success. http://jsfiddle.net/9HP9Q/1/ The table lines should have gray borders around them. It's working fine on all browsers except Internet Explorer 8. .order_table tab ...

Within a container, there are two divs separated by a white bar

Hello everyone, I am in need of creating a unique slideshow for my website and I want to start by splitting a div into two sections using a slightly skewed diagonal line that is either semi-transparent black or solid white. I have searched extensively onli ...

Steps to display a text box once the dropdown list is updated

I have a dropdown menu with two options <div class="form-group"> <span class="col-sm-4 control-span">Member Type</span> <div class="col-sm-8"> <select class="form-control" id="membertype" name="me ...

How to incorporate JSON into a d3.js calendar display?

Learning d3 charts and javascript has been quite challenging for me. After researching a lot, I successfully populated the chart with CSV data. Now, my next goal is to populate the chart with json data. This is the code I'm using, which is inspired ...

The Chocolat.js Lightbox plugin is experiencing issues with jQuery as it is unable to detect the

I am in the process of integrating chocolat.js into a basic website. An issue I encountered was that the thumbnail was directly processing the anchor link, which resulted in the image opening in a new window instead of launching it in a modal on the screen ...

Exploring the use of dictionaries within Django templates

views.py: return render(request,'images.html',temp) Temp Data: {'cluster1': ['temp/vinoth/cluster1/demo-pic94.jpg', 'temp/vinoth/cluster1/id1.jpg'], 'cluster2': ['temp/vinoth/cluster2/demo-pic94.jp ...

Cycle through items and switch states using classList in JavaScript

Rules: Your task is to utilize javascript and the classList property to switch the elements with the .highlight class. You need to loop through all the <li> elements and change the class of .highlight on each one. Do not make any changes to the HTML ...

Using Javascript, delete all chosen HTML elements containing innerText

Looking to extract certain HTML tags from a block of code in TextArea1 and display the modified output in TextArea2 upon clicking a button. <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8&quo ...

Calculating the time difference in days, hours, minutes, and seconds between two UNIX timestamps

I have a special occasion coming up, and the date and time for this event are stored in a Unix timestamp format. Instead of relying on a plugin like modern.js, I am trying to figure out the time difference between today's date and the event date usin ...

Attempting to align input fields and spans side by side

Is there a way to properly align multiple inputs next to each other with dots in between, resembling an IPv4 address? Currently, the span appears to float in the center. How can this be resolved? It's worth noting that all elements in the image have b ...

Steps to import shared CSS using Styled-components

In my project using react, I've implemented styled-components for styling. One requirement is to have a shared loading background. Here is the code snippet of how I defined it: const loadingAnimation = keyframes` 0% { background-position: 95% 95%; } ...

Minimize the use of globalized variables in your LESS CSS code

Is there a better way to avoid using globally diffused variables? I conducted a test with the following setup: _import.less @test: #FFF; _import2.less @test: #000; test.less @import (reference) "_import"; body { background: @test; } test2.less ...

Using inline JavaScript to style an element when clicked

Looking for assistance with styling a link. I've connected an external stylesheet to my HTML file, so that part is all set. The goal is to modify the text-decoration when the onclick event occurs. Here's what I currently have: <a class="dopel ...

Attempting to choose everything with the exception of a singular element using the not() function in Jquery

Within the mosaic (div #mosaique) are various div elements. My goal is to make it so that when I click on a specific div, like #langages or #libraries, the other divs become opaque while the selected div undergoes a size change (which works correctly in t ...

Utilizing opera and applying an inset box-shadow when active

Check out this link When viewing in Chrome, the button looks great. However, when switching to Opera, the box-shadow is not visible when the button is pressed (:active). This issue only occurs when the box-shadow on the :active state is set to inset, like ...

Webpack fails to handle CSS background images

I'm having trouble with my Webpack configuration as it's not processing CSS images set in the background property: background: url('./hero.jpg') no-repeat right; This is resulting in an error message that reads: ERROR in ./src/app/comp ...

Charting Add-Ons for jQuery

Looking for suggestions on user-friendly graph drawing plugins compatible with jQuery. Currently developing a web application that will retrieve data from a remote database and present it through visual graphs... Explored jgcharts (the jQuery Google Chart ...

Tips for creating a responsive iframe without relying on aspect ratio assumptions

Is there a way to create a responsive iframe without relying on a fixed aspect ratio? The width and height of the content are unknown until rendering. Keep in mind, using Javascript is an option. For instance: <div id="iframe-container"> <i ...