Unlimited icon carousel crafted with CSS

Currently, I have a set of 10 icons that are scrolling horizontally from right to left. However, I am encountering an issue where at the end of the icon loop, there is a space causing the icons to jump back to the beginning.

I am looking for a solution to remove this space at the end of the loop so that the slide can seamlessly continue from the first icon without any jumping. Essentially, I need to create a smooth and infinite loop effect.

Can someone assist me in resolving this problem?

.logo{width: 100%;}
.logo_slider {
  overflow: hidden;
width: 752px;
margin: auto;
}

.logo_slider {
  overflow: hidden;
}

.logo_slider ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  position: relative;
  animation: mymove 10s linear infinite;
}

.logo_slider ul li {
  flex-shrink: 0;
  flex-grow: 0;
  display: block;
  border: 1px solid #ccc;
  margin: 20px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
}

.logo_slider ul li a img {
  width: 100%;
}

/* Safari 4.0 - 8.0 */
@-webkit-keyframes mymove {
  0%    { left: 0; }
  100%  { left: -100%; }
}

/* Standard syntax */

@keyframes mymove {
  0%    { left: 0; }
  100%  { left: -100%; }
}
<div class="logo">
<div class="logo_slider">
<ul>
<li><a href=""><img src="https://upload.wikimedia.org/wikipedia/commons/a/ab/Android_O_Preview_Logo.png"></a></li>
<li><a href=""><img src="https://upload.wikimedia.org/wikipedia/commons/a/ab/Android_O_Preview_Logo.png"></a></li>
...
...
</ul>
</div>
</div>

Answer №1

Check out this Codepen demo


The concept here involves sliding the slider by a distance of 120px, which is equivalent to the width of one icon (each list-item measures 80px in width along with a 40px margin). Since all icons are identical, the transition appears seamless.

To optimize performance, the movement utilizes the transform property instead of left.

It's important to ensure that there are enough images to cover all viewport sizes (plus an additional one).

CSS Styles:

.logo_slider {
  overflow: hidden;
  width: 752px;
  margin: auto;
}

.logo_slider {
  overflow: hidden;
}

.logo_slider ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  animation: mymove 1s linear infinite;
}

.logo_slider ul li {
  flex-shrink: 0;
  display: block;
  border: 1px solid #ccc;
  margin: 20px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  box-sizing: border-box;
}

.logo_slider img {
  width: 100%;
}

@keyframes mymove {
  0%    { transform: 0; }
  100%  { transform: translateX(-120px); }
}

I would recommend using a single image for the icon and repeating it as a background (with the gray border part of the icon itself) rather than multiple images.

Here's an example employing a background:

View the Codepen demonstration here

In this method, the illusion of movement is achieved by setting the inner element's width (a pseudoelement :before containing the background) to the parent container's width plus 120px (using the calc() function).

The HTML markup is simple:

<div class="optimizedslider"></div>

And the corresponding CSS styling:

.optimizedslider {
  overflow: hidden;
  width: 750px;
  height: 100px;
  margin: auto;
}

.optimizedslider:before {
  content: "";
  display: block;
  background: url(https://url.to/icon.png) repeat-x;
  background-size: 120px 100px;
  height: 100%;
  width: calc(100% + 120px);
  animation: mymove 1s linear infinite;
}


@keyframes mymove {
  0%    { transform: 0; }
  100%  { transform: translateX(-120px); }
}

If needed, here is the icon (240x200) used:

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

Answer №2

Every time an icon moves off the screen, we simply remove it since nobody can see it anyway. Simultaneously, a new icon is generated on the other side of the screen to continue moving across the canvas. Update your animation called "mymove" with this code snippet:

@keyframes mymove {
  0%    { translate: 0; }
  100%  { transform: translateX(-120px) } 
}

The value of 120 px aligns closely with the width of one icon in your example. To create the desired illusion, make sure to have one additional icon beyond what you intend to display. For instance, if you want to show 6 icons, keep 7 so that the last one contributes to the visual effect.

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

The image link leading to the homepage lacks the functionality to be clicked on

My website has a logo on the top left that links to the home page, but only some areas of the image are clickable. It seems like the clickable and non-clickable areas are scattered randomly. How can I ensure that the link works across the entire area of ...

Unable to bring JavaScript into an HTML document

I am diving into the fundamentals of JS and HTML, starting with a simple script. Here is my test.js file: document.getElementById("test").innerHTML = "Loaded js file"; And here is my test.html: <!DOCTYPE HTML> <html lang="de"> <head> & ...

hover causing the table cell to act erratically

My table consists of three cells with widths of 30%, 40%, and 30% respectively. The table itself occupies 25% of its container, which can range from 1024px to 400px. The first cell contains a button labeled GALLERY. Upon hovering over the cell, the text c ...

Error message "Undefined is not a function" occurred while using jQuery's .replace and scrollTop functions

I'm having issues with the scroll function in my code. It doesn't seem to be able to locate the ids in my HTML, even though I can't figure out why. I had a previous version that worked perfectly fine (unfortunately, I didn't save it D:) ...

Conceal table columns on an HTML page using CSS styling

HTML: <table class="list qy"> <tr> <td>cell1</td> <td class="q">cell2</td> <td>cell3</td> <td class="y">cell4</td> </tr> </table> CSS: table.qy td.q, table.qy td.y { displ ...

Is it possible to scale images dynamically using CSS without losing their proper proportions?

http://jsfiddle.net/CJzCA/ Is there a way to resize images using CSS in the above jsfiddle? The keyboard images are currently too big compared to the text, and I usually solve this issue by using Photoshop. It would be more convenient if we could resize t ...

Is it possible to create a webpage that is invisible to users accessing it from a desktop device

Is it possible to create a webpage that is only visible on tablet and mobile devices, while redirecting desktop users somewhere else? I want this page to be hidden from desktop users entirely. ...

Issue with Audio TAG functionality in Internet Explorer 9

I am facing an issue with my jQuery code that generates an audio tag. The code works perfectly in Firefox and Chrome, but it is not functioning properly in IE9. Here is the code snippet: $(document).ready(function () { var source = "/TTS.aspx?tts=" + ...

Angular - Customizing button bindings for various functions

As a newcomer to Angular and TypeScript, I am faced with the task of creating a customizable button that can display text, an icon, or both. For example: button-icon-text-component.html <button> TEST BUTTON </button> app.component.html & ...

How can I position a CSS Grid grandchild outside the boundaries of its parent using Tailwind CSS?

I'm looking to create a CSS Grid layout where the grandchild element stretches to fit the width of its parent. Here's a demo showcasing my issue -> https://play.tailwindcss.com/jZdsHpPAad The CSS Grid Wrapper I have is as follows: <div cl ...

Tips for adding a space before the footer in a document

Implementing a Top Navigation Bar with grey spacing Avoid having any extra space just before the footer: Organizing my Layout File ("navigation_top" refers to the black navigation bar at the top) %body = render "navigation_top" .main-content .cont ...

Issue with Bootstrap 5 Card Header not extending to full width

I have implemented tables within cards using a CDN. While the table looks fine in wide widths, it does not resize to fill the entire width when squeezed. Below is the HTML code: <div class="card table-responsive"> <div clas ...

Exploring ngModel components with a specified class

In my HTML code, I've assigned many elements with ngModel defined as ng-model = "object.[something]". For example: <div class="form-group row" ng-model="object.askUser"> I use this method to keep my purpose clear for these elements. My questi ...

CSS exhibiting variations on similar pages

Although the pages look identical, they are actually pulled from the same template file in Drupal but have different URLs. nyc.thedelimagazine.com/snacks In my document head, I've included a style rule that overrides a stylesheet further up the casc ...

Chrome stack router outlet and the utilization of the Angular back button

I'm experiencing an issue with the back button on Chrome while using Angular 14. When I return to a previous page (URL), instead of deleting the current page components, it keeps adding more and more as I continue to press the back button (the deeper ...

What is the best way to access the iframe element?

This is main.html <body> <iframe id="frame" src="frame.html"></iframe> <script type="text/javascript"> document.getElementById('frame').contentWindow.document.getElementById('test').innerHtml = &apos ...

Error in RatingBar component: Vue.js 3 and Tailwind CSS not displaying dynamic width correctly

I have a component called RatingBar in Vue.js 3 with Tailwind CSS. My goal is to dynamically adjust the width of the parent element's class based on a value, but even though I see the desired width in DevTools, it always renders as 100%. Below is the ...

Is there a way to automatically play videos without any audio?

Is there a way for my video to automatically start playing when the page loads, without sound? I want it to function similar to the video on this webpage: . I've experimented with various jQuery, JavaScript, and CSS techniques from online resources, ...

Create a background for a dropdown list that appears unreachable, positioned above all other elements

I am encountering an issue with my autocomplete function where the drop down list appears unreadable as it is overlapping other elements on the page. The problem lies in the fact that I did not manually create the drop down list, but rather it is generate ...

Adjust the position of the xAxis on the Highcharts chart to move it downward or

I recently inherited some code from the previous developer that uses highcharts.js (v3.0.1). I'm having trouble with the xAxis appearing within the graph itself (see screenshot). Despite my efforts to recreate this issue in jsfiddle, I can't seem ...