Tips for designing a continuous horizontal-scrolling bar that loops the content indefinitely from left to right

Looking for some help as a beginner in programming and coding! I'm having trouble finding or creating the right code, any assistance would be highly appreciated!

Firstly, here's the CSS and HTML code I have:

CSS:

.LoopingScroll{
  overflow-x: auto;
  white-space: nowrap;
  max-width: 200px;
}

The HTML code is as follows:

<!doctype html>
<html>
 <head>
  <title>LoopingScroll</title>
  <link rel="stylesheet"
   href="style.css">
 </head>

 <body>

<table class="table"> 

    <thead>
        <tr> 
      <th>TestingA</th> 
      <th>TestingB</th>
      <th>TestingC</th>
    </tr> 
    </thead> 

  <tbody>   
      <tr class="active"> 
      <td>TestingD</td> 
      <td>TestingE</td>
      <td class="LoopingScroll"> 
        Testing01 Testing02
        Testing03 Testing04
        Testing05 Testing06
        Testing07 Testing08
      </td> 
    </tr> 
     </tbody> 

</table> 

  <script src="script.js">
  </script>
 </body>
</html>

Currently, I have a horizontal scrollbar that displays "Testing01" to "Testing08" which is good. But what I really want is for the content to loop when users scroll from "Testing01" to "Testing08" continuously. Essentially, I want the horizontal scrollbar to endlessly loop from testing 01 to testing 08 and repeat smoothly without requiring users to scroll left (unless they choose to).

The main issue I'm struggling with is: "Does anyone know of a recommended code solution for creating a looping horizontal scrollbar?"

Any suggestions would be greatly appreciated!

-Scholah

Answer №1

Check out this JavaScript solution:

document.addEventListener("DOMContentLoaded", function() {
  const scrollElement = document.querySelector('.LoopingScroll');
  let originalContent = scrollElement.innerHTML;
  let contentToAdd = originalContent;

  scrollElement.addEventListener('scroll', function() {
    let atRightEnd = (scrollElement.scrollWidth - scrollElement.scrollLeft - scrollElement.clientWidth) < 50;

    if (atRightEnd) {
      scrollElement.innerHTML += contentToAdd;
    }
  });
});
.LoopingScroll {
  overflow-x: auto;
  white-space: nowrap;
  max-width: 200px;
}
<table class="table">
  <thead>
    <tr>
      <th>TitleA</th>
      <th>TitleB</th>
      <th>TitleC</th>
    </tr>
  </thead>
  <tbody>
    <tr class="active">
      <td>ItemD</td>
      <td>ItemE</td>
      <td class="LoopingScroll">
        Item01 Item02 Item03 Item04 Item05 Item06 Item07 Item08
      </td>
    </tr>
  </tbody>
</table>

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

Using Webpack to Compile Sass (and keep class names local)

It's been a long journey trying to configure my Webpack setup to compile Sass, and the process has become quite overwhelming. In my quest for answers, I encountered numerous Github issues, Stackoverflow threads, and blog posts discussing how to integr ...

Display an asterisk or bullet point in text fields and labels to indicate that the user does not have permission to view

In my current project, I have a specific requirement that involves displaying an asterisk or bullet dot for fields which the user does not have view access to. My goal is to keep the labels visible but show them as read-only with the asterisk data. Furthe ...

Guide to positioning a logo at the center of a bootstrap navbar

I need help positioning my logo on the navbar without stretching it. How can I make sure it overlaps or doesn't affect the size of the navbar? <nav class="navbar navbar-expand-lg navbar-light bg-light"> <button class="navbar-togg ...

Display or conceal div elements using JavaScript

Is there a way to hide certain divs when clicking on a specific div box? Clicking on the box will trigger the hiding of some application divs. See the first image below: When the boxes are hidden, the other divs will readjust in place of the current divs ...

Encountering an issue when passing an object during the creation of dynamic HTML

I am dynamically generating HTML for a bootstrap Modal and attaching it to the body element as shown below. Modal HTML function GenerateConfirmationModalHTML(HeaderMessage, Message,YesEvent, Noevent) { var html = '<div id="clearModal"> ...

Using CSS3 easing on Mobile Safari can help create smooth transitions

Can anyone advise on how to recreate the easing/friction for touch events in Mobile Safari? I am trying to achieve a similar bounce-back effect when dragging contents past the top or bottom of a scroller. I experimented with the cubic-bezier easing functi ...

Is there a problem in Angular 2 and Ionic 2 *ngfor where clicking on one element causes changes to all elements?

When I click on the playNote(note) function, why does it change all instances of [name]="myIcon" in my ngFor loop? I only want to change the icon of the one that was clicked... home.html <ion-item color="theme" class="note-block" *ngFor="let note of n ...

What is the best way to connect added elements together?

I am currently utilizing Plupload to upload files. Due to specific requirements, I need to place FilesAdded "inside" init as demonstrated below. The issue I'm facing is the inability to utilize jQuery.remove() on elements that have been appended usin ...

leveraging Excel input for data manipulation in Java

I am looking to create a code that will help me generate a line of flight using data from an Excel spreadsheet. The process involves calculating the time between flights, ensuring the plane has enough time on the ground before taking off again, and determi ...

If the function window.location.href.indexOf is malfunctioning

In order to display a specific element only when the location is correct, it should not appear otherwise. The following code is not functioning as expected: <div *ngIf="!accessTrue() && window.location.href.indexOf('something') > ...

Tips for enhancing a table with extra functionality in Angular 6

Hi there! I've created a table using Angular 6 and now I'm looking to enhance it with some extra functionality: Implement an overall table search feature Allow users to sort the table by columns Add a "Page x of n" option for pagination I woul ...

jQuery for advanced DOM manipulation

My webpage has a structure similar to this: <ul> <li> <div class="truc"></div> <div class="machin"></div> <div class="chose"></div> </li> <li> <div ...

The upload functionality in Codeigniter seems to be malfunctioning

I am currently developing a content management system using Codeigniter. I am facing an issue with uploading files from the system. Although I am able to receive the file, the do_upload method seems to be not functioning correctly. I have looked for soluti ...

Vanilla JavaScript error: Unable to access property

I am working on implementing a header with a logo and navigation that includes a menu toggle link for smaller viewports. My goal is to achieve this using Vanilla JS instead of jQuery. However, when I click on the menu toggle link, I encounter the followin ...

Is your mobile responsive dropdown causing issues with content placement?

After implementing a bootstrap header that collapses into a dropdown menu, I noticed that the content below it was being pushed down when the image moved properly but the text on the image did not. Even though the image moves correctly when the dropdown is ...

Encountering an error while trying to load a CSS file in a React project using webpack due

I'm currently working on a React project that utilizes styled components, and I've been attempting to integrate a CSS file as part of the react-image-gallery package. Following the instructions provided, I included the css-loader and style-loade ...

Is there a chance that unused fonts included in @font-face are still being requested by browsers?

Curiosity Do browsers fetch and download all the files specified in @font-face declarations or do they grab only the ones referenced in stylesheets? For Instance Imagine I have these 3 @font-face declarations: @font-face { font-family: 'A'; ...

Is the textarea functioning properly with the inclusion of mysterious character variables?

As per the documentation When using an unknown named character reference like &this, it results in an ambiguous ampersand error. This situation is confusing <textarea> &this </textarea> What am I misunderstanding here? Any re ...

Utilize AngularJS to import a unique custom css stylesheet for every individual webpage

Is there a way to apply different stylesheets to each page without mixing classes? For example, how can I link style.css to index.html and about.css to about.html? This is my AngularJS code: // Define module var myApp = angular.module('myApp', ...

Displaying the active navigation element in ApyCom JavaScript jQuery menu: tips and tricks

Currently, I am utilizing the jQuery navigation menu from ApyCom. Everything seems to be functioning properly except for one issue. Whenever I click on a different navigation element, I expect that element to remain highlighted in order to indicate to the ...