What could be causing the elements in my slider to not repeat as they should?

The slider I came across on CodePen caught my eye. I decided to tweak it and incorporate images with varying sizes into the mix. However, there's an issue – when all the logos slide away, the slider abruptly jumps back to the first logo. It disrupts the flow and doesn't look aesthetically pleasing. What I am aiming for is a seamless repeating effect where after the last logo slides off, the first one smoothly appears without any noticeable "jump".

How can I go about resolving this dilemma?

body,
html {
  height: 100%;
  background-color: white;
}

.container {
  overflow: hidden;
}

.container .slider {
  animation: slidein 30s linear infinite;
  white-space: nowrap;
}

.container .slider .logos {
  width: 100%;
  display: inline-block;
  margin: 0px 0;
}

.container .slider .logos .fab {
  width: calc(100% / 5);
  animation: fade-in 0.5s cubic-bezier(0.455, 0.03, 0.515, 0.955) forwards;
}

@keyframes slidein {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(-100%, 0, 0);
  }
}

@keyframes fade-in {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
<div class="container h-100">
  <div class="row align-items-center h-100">
    <div class="container rounded">
      <h1 class="text-center">Featured in:</h1>
      <div class="slider">
        <div class="logos">
          <img src="https://via.placeholder.com/80">
          <img src="https://via.placeholder.com/80">
          <img src="https://via.placeholder.com/80">
          <img src="https://via.placeholder.com/80">
        </div>
      </div>
    </div>
  </div>
</div>

Answer №1

Modify the following code snippet:

.container {
  overflow: hidden;
  .slider {
    animation: slidein 30s linear infinite;
    white-space: nowrap;
    .logos {
      width: 100%;
      display: inline-block;
      margin: 0px 0;
      .fab {
        width: calc(100% / 5);
        animation: fade-in 0.5s 
          cubic-bezier(0.455, 0.03, 0.515, 0.955) forwards;
      }
    }
  }
}

to this updated version:

.container {
  overflow: hidden;
  .slider {
    animation: slidein 30s linear infinite;
    white-space: nowrap;
    .logos {
      width: 100%;
      display: inline-block;
      margin: 0px 0;
      img {
        width: calc(100% / 5);
        animation: fade-in 0.5s 
          cubic-bezier(0.455, 0.03, 0.515, 0.955) forwards;
      }
    }
  }
}

Answer №2

After replacing the Font Awesome icons with images, it is crucial to update the selector in the CSS accordingly. Additionally, ensure that the quantity of images is considered in the CSS width calculation for proper alignment.

It's worth noting that in the original demo, the images were duplicated in the markup twice. This step should not be overlooked during the modification process.

To make the slider self-sufficient and independent from surrounding markup, any reliance on external elements has been eliminated.

.slider {
  white-space: nowrap;
  overflow: hidden;
}

.slider-inner {
  animation: slidein 30s linear infinite;
}

.slider .logos {
  width: 100%;
  display: inline-block;
  margin: 0px 0;
}

.slider .logos img {  /* updated selector */
  width: calc(100% / 4);  /* must match the number of elements in your slider */
  animation: fade-in 0.5s cubic-bezier(0.455, 0.03, 0.515, 0.955) forwards;
}

@keyframes slidein {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(-100%, 0, 0);
  }
}

@keyframes fade-in {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
<h1 class="text-center">Featured in:</h1>

<div class="slider">
  <div class="slider-inner">

    <!-- must be included twice -->
    <div class="logos">
      <img src="https://via.placeholder.com/200">
      <img src="https://via.placeholder.com/200">
      <img src="https://via.placeholder.com/200">
      <img src="https://via.placeholder.com/200/ff0000">
    </div>

    <div class="logos">
      <img src="https://via.placeholder.com/200">
      <img src="https://via.placeholder.com/200">
      <img src="https://via.placeholder.com/200">
      <img src="https://via.placeholder.com/200/ff0000">
    </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

Numerous status buttons with a variety of background colors

There are 3 buttons on the order page: [New Order], [Processing], and [Completed]. When the processing button is clicked, the background of the button should change and the order status will be updated in the database. The [New Order] button will have a ...

Guide: Passing a multi-line string as props within a React component

I need to pass a long string as a prop to one of my components, but the text needs to be separated into multiple paragraphs. I attempted using '\n' for line breaks, but it didn't work as expected. Here is an example of the code: <Si ...

Listening for changes in a variable using a YUI event listener

/* Creating an event listener for the submit button */ YAHOO.util.Event.addListener(webserver.result_form, 'submit', webserver.result_submit); In my main.js, I currently have this event listener set up. I was curious to know if in YUI there is ...

What steps can be taken in Next.js to display a 404 page when data is not retrieved from the Wordpress admin?

I am working with JSON data that looks like this: [ { "taxonomy_slug": "product_cat", "taxonomy_name": "Categories", "frontend_slug": "product-category" }, { ...

I am having trouble getting two similar Javascript codes to function simultaneously

Using a common JavaScript code, I am able to display a div when a certain value is selected. http://jsfiddle.net/FvMYz/ $(function() { $('#craft').change(function(){ $('.colors').hide(); $('#' + $(this ...

Using Regex to detect recurrent (similar) patterns in jQuery <input> tags

I need assistance with ensuring that users input article numbers in the correct format, like this: ABC_ABC123; AB__B2A4; ABF_323WET; ... Currently, I have a regex pattern that works for one article number: var mask1 = /^([A-Z]{2})([A-Z|_]{1})_([A-Z0-9]{ ...

Styling Tip: Removing a header from the initial page of a chapter using CSS

Using CSS to generate HTML to PDF, I have successfully added page numbers at the bottom and chapter names at the top of each page using @top-center in the CSS and HTML code below. The rendering is done with Prince. However, I need a way to exclude the hea ...

Issue with AngularJS filter not functioning properly

I have a specific situation where I am using an ng-repeat directive in the following manner: {"ng-repeat" => "city in cities() | filter: search"} In this context, each city object is structured like so: { attributes: {name: 'Boston'} } Furt ...

Pause jQuery at the conclusion and head back to the beginning

As a beginner in the world of jQuery, I am eager to create a slider for my website. My goal is to design a slideshow that can loop infinitely with simplicity. Should I manually count the number of <li> elements or images, calculate their width, and ...

IDEA Live Template for Javascript variable printing feature

When coding in Java, I utilize a live template called soutv. This allows me to simply type myVar and it automatically duplicates it resulting in: System.out.println("myVar = " + myVar); Is there a way for me to create a similar custom live template for J ...

"Steady layout of grid for the navigation bar and

Currently, I am in the process of developing a control panel with the use of HTML and CSS. To structure the page, I opted for a grid layout. However, I encountered an issue where the navbar and sidebar do not stay fixed on the screen despite trying various ...

What could be causing Html.checkboxfor to fail in updating the boolean value of the model?

I am currently working on a project where customers can select multiple users to remove them from the database. The issue I'm facing is that the checkboxes are not changing or sending the isSelected variable, which tells the server which users should ...

Managing the layout with React Native Flexbox to evenly distribute items

Check out this React Native Demo I put together featuring Santa images being added and removed in a Flexbox. Bunch of Santas I noticed that when there are more than 3 Santas, the layout shifts to the left. I'm curious about how to keep the Santas ce ...

What is the best way to remove all HTML tags from a JSON file?

I'm looking for a way to efficiently clean up a JSON file that contains improperly extracted HTML content. I need to remove all text that is enclosed in HTML tags, along with the tags themselves. I attempted to use this function: def eliminateHTML(s ...

What is the best way to retrieve a random amount of lines of data from the stdin in Node.js?

Currently, I am attempting to execute a basic program in the Visual Studio Code terminal using node.js. This program involves reading inputs from the user, performing operations on those inputs, and displaying the results. Despite trying various methods, ...

Tips for Incorporating Multiple Functions in an HTML Form Submission for Validation Using JavaScript

Having some trouble with my HTML form. I created a function to validate passwords and check if the username is already taken. The form should submit only when both checks pass, but it's not working as expected. I have confirmed that the issue is no ...

It seems like my ajax function is functioning properly, but the data is not getting submitted

Having trouble sending the value of my selector to a PHP file through AJAX. The success function is working, and when I directly visit "your_php_script.php" it functions as expected. However, why is the PHP page not showing up on the page with the AJAX r ...

Having trouble creating a table using a JSON object in AngularJS

Click here to view the converted JSON object Please pay close attention to my question Hello, in the code below I am attempting to convert XML data into a JSON object. With this converted JSON object, I am aiming to create a table using AngularJS. The is ...

Getting a hold of an Array value from an external scope in Angular JS

I've been struggling with this issue for a while and can't seem to find a solution. I have a code snippet where I'm trying to pass values from getJSON to an angular controller, but my array loses its values in the process. Can someone please ...

How can we ensure that the entire BS4 Navbar (on smaller screens) is clickable, allowing users to show/hide the submenu by touching anywhere within the area?

https://i.sstatic.net/03po7.png My goal is to make the entire navbar area touchable, rather than just having a button. I believe this can be achieved by adjusting the default Bootstrap 4 navbar settings: HTML: <nav id="menu-navbar" class="navbar navb ...