move list items in a horizontal animation

I have a mini image carousel displaying 8 pictures, but only showing 5 at a time while the others remain hidden.

Here is the HTML structure:

<div id="itemsListBox">
    <ul>
        <li><img src="images/home-items/washing_machine.png" alt="" /></li>
        <li><img src="images/home-items/refrigerator.png" alt="" /></li>
        <li><img src="images/home-items/dishwasher.png" alt="" /></li>
        <li><img src="images/home-items/ovens_stoves_hobs.png" alt="" /></li>
        <li><img src="images/home-items/extractors.png" alt="" /></li>
        <li><img src="images/home-items/microwave_oven.png" alt="" /></li>
        <li><img src="images/home-items/coffee_makers.png" alt="" /></li>
        <li><img src="images/home-items/washer_dryer.png" alt="" /></li>
        <li><img src="images/home-items/tumble_dryer.png" alt="" /></li>
    </ul>
</div>

Below is the corresponding CSS styling:

#itemsListBox {
    position: absolute;
    top: 90px;
    width: 100%;
    padding: 0 10%;
    overflow: hidden;
}
#itemsListBox ul {
    white-space: nowrap;
    overflow: hidden;
}
#itemsListBox ul li{
    list-style-type: none;
    display: inline-block;
    width: 18%;
    margin: 1%;
}
#itemsListBox ul li img {
    width: 100%;    
}

To add animation when moving images, you can use this JavaScript code:

$("#rightArrow").click(function(e) {
        var curr =  $("#itemsListBox ul li:last");
        curr.parent().prepend(curr);
    });
$("#leftArrow").click(function(e) {
        var curr =  $("#itemsListBox ul li:first");
        curr.parent().append(curr);
    });

If you want to enhance the transition with animations, consider using jQuery effects. Any suggestions?

Check out the live demo here: http://jsfiddle.net/Bergkamp/shnyH/

Answer №1

If you're looking to achieve a similar effect, consider setting the image position as relative in your CSS:

 img {position:relative;}

Instead of using append and prepend, try utilizing the animate function of jQuery to alter the left position:

   $("img").animate({ 
    left: "-=150px",
  }, "slow" );

For a visual example, check out this edited demo: http://jsfiddle.net/z3PzC/

Answer №2

Check out this cool slide down/slide up animation example using your images: http://jsfiddle.net/Jag96/5VDTL/

The challenge here lies in the fact that only 5 images are displayed at a time, so the animation needs to target the first and fifth li elements:

$("#itemsListBox ul li:nth-child(5)").slideUp("slow", function () {
    curr.hide().prependTo(curr.parent()).slideDown();
});

If you want more control over your animations, you can also explore using jQuery's .animate() method.

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

Styling the active selection in nav class with bold attribute in Bootstrap/AngularJs

How can I apply the bold attribute to the currently selected nav bar item? <ul class="nav"> <li role="presentation" ng-repeate="item in items" ng-class="{'active':navLink == item.header}"> </li> &l ...

Keyword highlighting on the go

Does anyone know how to implement keyword highlighting in a PHP search script using HTML tags? This is the current code I am working with: if(!empty($_GET['q'])){ $keywords=explode(' ',$_GET['q']); foreach($keywords as $quer ...

Retrieving the current DOM element in Vue's styling

My goal is to incorporate a transform effect that only applies to the hovered video or image. The effect is dynamically computed and cannot be implemented directly in a Vue method, but I am exploring the option of modifying the target element for the useMo ...

Check your jQuery regex to see if a variable starts with another

Is it possible to check if a variable starts with another one? For example, checking if Var1 starts with Var2 let regex = '^'+var1+'i'; if(regex.match(var2)){ return true } This code snippet always fails to return true. Thank you in ...

Problem with the fixed header on a container causing a horizontal scroll bar

This scenario presents a bit of a challenge! I could solve it by adjusting the container's height, but that would disrupt the fixed position of the sticky header. My goal is to have a scrollbar visible in both the X and Y directions on the .scrollabl ...

Utilizing React Developer Tools to easily click a button

Currently, I am working on building a card in React with Material UI. Here is the layout: https://i.sstatic.net/CFS58.png The button labeled Sign out has the functionality to change its state from true to false using React developer tools. However, I am ...

In my development environment, the page does not have scroll functionality, but in the production environment, it is scrollable

Whenever I open a table or any other element with overflowing content, I encounter an issue with the scrolling bar. Even though the CSS includes overflow-y: scroll;, the scroll bar on the right remains in gray and does not allow me to scroll down when the ...

Update a specific division

Looking for suggestions on how to automatically refresh a div? I'm currently developing a chess game and I need the div to reload every time one player updates data in the database. The game is almost complete, but there's an issue where Player ...

The surprising margins that Bootstrap sneaks into columns

It seems like bootstrap is mysteriously including an unseen margin in my column classes. Even after inspecting an element labeled as 'col-lg-3,' there is no visible margin CSS, and attempting to manually add margin:0 still results in a margin bei ...

A guide to making cross-origin HTTP GET requests with AngularJS utilizing the Food2Fork API

I am attempting to send a get request using the food2fork search api within my angular application. As of now, there is no backend connected to the app, so everything operates on the client side. The code snippet I am using is as follows (with the APIKEY r ...

Re-activate a disabled Angular mat-select field

I am facing an issue with a mat-select field on a form that serves dual purposes. Firstly, it is used to select specific values to include in a data element when searching for records. Secondly, once a record is found, it displays the value of the data ele ...

What is the best way to center-align a child DIV (not vertically)?

After spending an entire day searching for a solution to align my child DIV from its parent, I realized that all my research led me to the same results. This is my first attempt at creating a webpage. Check out the result here. View the code on https:// ...

Creating a two-column layout in React with Material-UI to display repeated information

I'm currently developing a component using Grid, and I would like the information to display in two columns instead of just one. I'm having trouble figuring out how to achieve this. I understand that I could potentially add another Grid section w ...

Is there a way to reduce the space occupied by my SVG and why am I encountering limitations in resizing it?

The issue with SVG extra space persisting even after trying various fixes is driving me crazy. When inspecting the SVG, there seems to be a large blue space that is pushing everything else down. I have experimented with different solutions like setting hei ...

Is the button not aligned properly with the email input field?

<div class="subscribe__form--action--btn"> <form action="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32545b5e5b5746545C5B5356477F54585850"> </a>" meth ...

Confirming the structure of a URL using JavaScript/jQuery

I have a text field where users input URLs. I need to validate the format of the URL using regular expressions. Specifically, I am looking for invalid URLs such as: http://www.google.com//test/index.html //Invalid due to double slash after hostname http: ...

Discover the vertical measurement of a group with jquery

Among a group of child divs sharing the same class name, only one div will be visible depending on the user's selection while the others are hidden with the display: none; property. Is there a method to determine the height of the div currently in vi ...

What is the most effective method for attempting an AJAX request again after it fails with the help of jQuery?

Here is a suggestion for handling ajax errors: $(document).ajaxError(function(e, xhr, options, error) { xhr.retry() }) An improvement could be incorporating exponential back-off strategies ...

How can I use javascript or jquery to access elements generated by a repeater in asp.net?

I have a scenario where I am working with a master page and a repeater. My goal is to implement a selective use of required field validators based on user selection. Specifically, when the "Yes" option is chosen (corresponding to the ListItem with the valu ...

Validation of Email Existence (Using Django and Javascript/Ajax)

I'm currently facing a challenge with building an E-mail validator using Django and Javascript/Ajax. Despite my efforts, I seem to be stuck at a certain point where the Ajax response consistently shows: {response: "This field is required.", email: fa ...