Continuously slide the client's logo from right to left in an endless loop

I have implemented the following code to create an infinite slider for my client's logo. The slider moves from right to left and I am using jQuery to add duplicate slides to ensure the loop continues seamlessly.

However, I am facing a particular issue where the code resets automatically after the slider reaches the fourth card. Can anyone provide insight on what might be causing this problem?

 $(document).ready(function() {
    // Clone cards to create infinite loop
    $(".marqueme").clone().appendTo(".marquestarthere");

  });
 .testimonial-cards {
  list-style: none;
  display: flex;
  gap: 56px 31px;
  margin: 0 auto;
  width: max-content;
  flex-wrap: nowrap;
}

.testimonial-cards li {
  width: 100%;
  max-width: 500px;
  min-height: 200px;
}

.marqueslide .marqueme {
  flex: 0 0 auto;
  margin-right: 20px;
  border:1px solid #000
}


/* solution */

.marquestarthere {
  animation: marquee 8s linear infinite; /* Set the animation here */
}

.marquestarthere:hover{
  animation-play-state: paused;
}

@keyframes marquee {
  0%,100% {
    transform: translateX(0);
  }
  99.999% {
    transform: translateX(-50%);
  }
}
<div class="marqueslide">
    <ul class="testimonial-cards marquestarthere">

    <li class="marqueme">Card 1</li>
    <li class="marqueme">Card 2</li>
    <li class="marqueme">Card 3</li>
    <li class="marqueme">Card 4</li>
    <li class="marqueme">Card 5</li>
    <li class="marqueme">Card 6</li>
    <li class="marqueme">Card 7</li>
    <li class="marqueme">Card 8</li>
    <li class="marqueme">Card 9</li>
    <li class="marqueme">Card 10</li>

    <!-- duplicate cards append here-->
</ul>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

Answer №1

        $(document).ready(function() {
            // Replicate list items for continuous loop
            $(".marqueslide .marqueme").slice(0, 4).clone().appendTo(".marquestarthere");
        });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<div class="marqueslide">
    <ul class="testimonial-cards marquestarthere">
        <li class="marqueme">Option 1</li>
        <li class="marqueme">Option 2</li>
        <li class="marqueme">Option 3</li>
        <li class="marqueme">Option 4</li>
        <!-- Cloned list items will be inserted here -->
    </ul>
    </div>

The problem you are facing may stem from how you are duplicating the slides. It appears that you are copying the entire .marqueme element and pasting it into .marquestarthere, leading to a duplication of the entire list. Instead, consider cloning individual list items and appending them correctly.

Below is the revised jQuery code for proper duplication and insertion of list items:

$(document).ready(function() {
    // Replicate list items for continuous loop
    $(".marqueslide .marqueme").slice(0, 4).clone().appendTo(".marquestarthere");
});

Additionally, here is the updated HTML structure:

<div class="marqueslide">
<ul class="testimonial-cards marquestarthere">
    <li class="marqueme">Option 1</li>
    <li class="marqueme">Option 2</li>
    <li class="marqueme">Option 3</li>
    <li class="marqueme">Option 4</li>
    <!-- Cloned list items will be inserted here -->
</ul>

This approach will clone the first four list items (options) and insert them at the end of the list, achieving the desired continuous loop effect.

Answer №2

 $(document).ready(function() {
    // Clone cards to create infinite loop
    $(".marqueme").clone().appendTo(".marquestarthere");

  });
 .testimonial-cards {
  list-style: none;
  display: flex;
  gap: 56px 31px;
  margin: 0 auto;
  width: max-content;
  flex-wrap: nowrap;
}

.testimonial-cards li {
  max-width: 500px;
  height: auto;
   aspect-ratio: 1/1;
   
}

.marqueslide .marqueme {
  flex: 0 0 auto;
  margin-right: 20px;
  border:1px solid #000
}


/* solution */

.marquestarthere {
  animation: marquee 8s linear infinite; /* Set the animation here */
}

.marquestarthere:hover{
  animation-play-state: paused;
}

@keyframes marquee {
  0%,100% {
    transform: translateX(0);
  }
  99.999% {
    transform: translateX(-50%);
  }
}
<div class="marqueslide">
    <ul class="testimonial-cards marquestarthere">

    <li class="marqueme">Card 1</li>
    <li class="marqueme">Card 2</li>
    <li class="marqueme">Card 3</li>
    <li class="marqueme">Card 4</li>
    <li class="marqueme">Card 5</li>
    <li class="marqueme">Card 6</li>
    <li class="marqueme">Card 7</li>
    <li class="marqueme">Card 8</li>
    <li class="marqueme">Card 9</li>
    <li class="marqueme">Card 10</li>

    <!-- duplicate cards append here-->
</ul>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

There seems to be a challenge with the card widths, causing the last card not to fully display before the animation ends. Removing width: 100% from li resolves this issue. You can adjust the size as needed and update the translateX value accordingly.

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

suggestions for organizing data in an AJAX/jQuery page

Welcome to my JavaScript/Ajax webpage that also utilizes jQuery. I am facing a challenge with displaying a nested structure. Once a top level element is displayed, users should be able to click on it and reveal the levels below (which are dynamically gene ...

What is the method for adjusting the input text color in a textarea to green?

Is there a way to change the input color for this textarea so I can type green text on a black background? textarea{ background-color: black; } <textarea id="htmlCode" class="1111" placeholder="HTML"></textarea> ...

JavaScript validation controls do not function properly when enabled on the client side

Following the requirements, I have disabled all validation controls on the page during the PageLoad event on the server side. When the submit button is clicked, I want to activate the validations and check if the page is valid for submission. If not, then ...

In Typescript, try/catch blocks do not capture return values

I am currently working on a function that performs database operations, with the implementation contained within a try/catch block. Here is an example: async function update({id, ...changes}): Promise<IUserResult> { try { //insert code here retu ...

Can you use JQuery to limit the number of list items displayed to only four, removing any extras

How can I navigate from class="Mr Richard Has Lots of Trees" to class="MrContent", locate class="Stuff", and display only four li elements while removing the last one? I'm currently trying to grasp Jquery but struggling to understand it. <div id= ...

How can you use jQuery to add a select element dynamically and then clear the selected choice?

Trying to build a dynamic form in the Play Framework, but my javascript skills are lacking. I found this jQuery example for adding fields dynamically, but I want to add both a text field and a select box each time. My attempt involves using this answer ...

Utilizing Three.js to Upload Images and Apply Them as Textures

While attempting to upload an image via URL and set it as a texture, I encountered an issue. The error message THREE.WebGLState: DOMException: Failed to execute 'texImage2D' on 'WebGLRenderingContext': Tainted canvases may not be loaded ...

What is causing this issue with my jQuery UI animation?

Below is the HTML code snippet: <div id="menu_status_item"> <span class="menu_status_bar"></span> </div> Here is the CSS code: #menu_status_item { margin-top: 40px; width: 100%; } .menu_status_bar { margin-le ...

An issue occurred in the evaluation of tidy when attempting to access the object 'titles' in the mask

Whenever I attempt to run this code, an error pops up. My goal is to extract data from multiple pages. However, when executing the script below, I encounter the following error message: Error in eval_tidy (xs [[j]], mask): object 'titles' not f ...

What is the best way to encapsulate multiple Bluebird promises within a single promise?

Seeking assistance in creating an async wrapper for a redis query supported by a db query. If the redis query fails, I want to execute the db query instead. When the db query is successful, I aim to store the returned data in redis before sending it back. ...

Refresh client web pages with JSON data without using eval

I am currently working as a consultant on a web application that functions as a single page app. The main purpose of the app is to constantly fetch new json data in the background (approximately every minute) and then display it on the screen. Our clients ...

Issue with CSS3 animations

.button { background-color: #4CAF50; /* Green */ border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; ...

Choose a specific date to set as the starting date using the dynamic

I used jQuery to dynamically create an HTML table with 3 rows, each containing input textboxes. The table fields are: SlNo Fee ST TotalAmt DueDate For the first row, the start date of the DueDate should be the current date. F ...

Utilize dependency injection to connect services with controllers located in separate files

In my storage.js file, I have defined a controller and service as follows: angular.module('app', []). controller('storageController', ['$scope', 'storage', function ($scope, storage) { ...

The modal fails to display when the content is positioned below a setInterval function

i have created a notification system using ajax currently, I am attempting to open a modal by clicking on the content of the notification with setInterval the modal works perfectly when the content of my notification is not being updated via setInterval. ...

Tips on showcasing an array as a matrix with a neat line property

I am currently developing an application using TypeScript, and utilizing a JSON array structured like this: data = [{"name":"dog", "line":1}, {"name":"cet", "line":1}, ...

Discovering JSON data embedded within a script tag in an HTML response using Jsoup

Looking for help with extracting JSON content from script tags embedded in an HTML file. I attempted to use Jsoup without success. Can anyone provide guidance on utilizing JSOUP or another library for this task? Thank you in advance. ...

Having Trouble with My PHP Contact Form Online

My website's PHP contact form, based on a bootstrap template, is not functioning properly. I am looking for guidance on how to create or obtain the necessary PHP/AJAX scripts to ensure the form works correctly. Any suggestions or feedback about my con ...

How to Calculate Dates in Javascript

Currently exploring the realm of JavaScript, I find myself in the process of developing a dashboard for an e-commerce platform that I am currently involved with. My goal is to display data for all dates starting from the date of the initial order placed. M ...

Marionette stores a collection for various item views

I am currently working on a project involving a composite view called QueueItems, with each item in the collection having its own itemView for modification. The challenge lies in allowing each element to select from multiple tag collections like States, Co ...