Having trouble getting the .animate method to work properly when applied to three different divs?

I have a code snippet below that enables swiping between different divs when an image is clicked.

The issue I am facing is that I am only able to swipe between the red and green divs, but I want to achieve a swipe sequence of red > green > blue. Any suggestions on how I can make this happen?

Thank you in advance!

/* The following are individual divs that can be scrolled through */
#left {
    min-width:100%;
    min-height:300px;
    background:red;
    position:absolute;
    top: 0;
    left:0;
}
#right {
    min-width:100%;
    min-height:300px;
    background:blue;
    position:absolute;
    top: 0; 
    right:-105%;
}
#middle {
    min-width:100%;
    min-height:300px;
    background:green;
    position:absolute;
    top: 0;
    right:-205%;
}

JS/JQuery:

<script>
    $(document).ready(function() {

    //Scroll all content to the left <---- like this
    $('#scrollRight').click(function(e) {  

            $('.container').animate({'left': '-105%'});             

        });

        //Scroll all content to the right ----> like this
    $('#scrollLeft').click(function(e) {  
    $('.container').animate({'left': '0%'});        

        });         

    //End document ready function.      
    });
    </script>

HTML:

<div class="container"> 
            <!-- Add the last div first so that each subsequent div will follow...ensuring the initial div you want visible is in the first position -->

            <div id="right">right scroll</div>  
            <div id="middle">left scroll</div>          
            <div id="left">left scroll</div>

    </div>

Check out the Fiddle here:

http://jsfiddle.net/45g3Le59/

Answer №1

When all three DIVs animate simultaneously, it may appear as if only two slides are being animated. To address this issue, introduce a delay between each animation.

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

Looping through the list items and attaching click listeners to them

Take a look at the code snippet below: // Loop through every child element for(j = 0; j < len; j++) { var entry = sortedArray[j]; // Create a new <li> element to hold each entry var entryLI = document.createElemen ...

Avoiding uib-popover from getting clipped by uib-carousel

I have a small widget with a popover that works fine when placed inside a div, but gets clipped when inserted into a carousel. Here's an example to illustrate what I mean: (The top image shows the widget in a div without clipping) https://i.sstatic. ...

Data is nowhere to be found despite using the post method, but the URL still contains valuable information

Recently, I've delved into the world of PHP and have been experimenting with HTML forms. Initially, I used the method GET which worked perfectly fine. However, when I switched to using the method POST, I encountered an issue where I couldn't retr ...

Limiting keyboard input with a phone number in a gridcolumn tag: A step-by-step guide

I have a query regarding a code line that is used to input a phone number into a designated box. <GridColumn field="phoneNumber" title="Phone Number" editor="text"/> Currently, I am able to enter any text using the key ...

Chrome is having trouble displaying Roboto font correctly

I have been experiencing an issue with the rendering of the Roboto font on a client's website. When I view the site in Chrome (version 43.0.2357.65 m), all the different weights of Roboto appear to look the same. For example, here is a comparison: On ...

Having trouble with the image not showing up using the code <img src="">

UPDATE :: I recently discovered that there is a permission error preventing me from accessing images in the images folder. It seems that I do not have the necessary "permission" to retrieve the image files ... * A few days ago, I posted a question regardi ...

A guide on incorporating a link to an external website once a Card is clicked in React JS

I have a code snippet for the Cards.js file that displays a card which links to the Services page on my website. I now want to add a link to an external website. How can I achieve this? Do I need to include an <a href= link in the Cards.js file? import ...

Developing a HTML button through Javascript that triggers a method with a single parameter when clicked

My current project involves creating HTML buttons through JavaScript using AJAX. Each time I click one of these buttons, it triggers an AJAX function. If the AJAX request is successful, it retrieves a number that will be utilized in a for loop. As the loop ...

Tips for moving a specific menu item to the right in bootstrap 4

Currently, I am integrating Bootstrap 4 into a Laravel 8 blog platform that I am working on. While the menu items are correctly positioned, I am facing an issue where I need to move the last menu item to the right. Despite trying various options like ml- ...

Creating personalized Bootstrap components

I am attempting to achieve a custom content layout in bootstrap that resembles the design of https://i.sstatic.net/nSK23.jpg However, I am facing an issue where the div with the black background overflows the parent div. Below is the code snippet: <d ...

Pattern to locate a CSS class identifier

I've been working on creating a regex to match valid CSS class name structures. Currently, my progress looks like this: $pattern = "([A-Za-z]*\.[A-Za-z]+\s*{)"; $regex = preg_match_all($pattern, $html, $matches); However, there are certai ...

The overflow scroll feature is activated, causing the background to appear greyed out, yet the

I've been struggling for hours to achieve this layout: Check out the code example here html, body { height: 100%; overflow-y: hidden; overflow-x: hidden; margin: 0px; padding: 0px; } .MyNavbar { height: 30px; background-color: red; } ...

What could be causing the inconsistency in my CSS performance in IE8?

I am encountering an issue with the CSS on my website specifically in IE8. The problem lies within the CSS intended to outline input elements labeled with class="error" with a 2px red border. While this function performs as expected for some input elements ...

Background images flanking both sides

What is the solution to making this function properly? <html> <head> <style type="text/css"> .left { float: left; background-image: url('image_with_variable_width.png'); background-repeat: repeat-y; } .right { float: right; bac ...

How can I eliminate the CSS value that was inherited?

Looking for a way to eliminate the effect of an inherited CSS property with Jquery. .class1 #id1 div.class2 input.class-input{ border-color: #bbb3b9 #c7c1c6 #c7c1c6; } Can someone explain how to delete this "border-color"? Thanks. ...

designing a CSS layout with content that fills the height

I'm facing a challenge with CSS as I work on adapting a website. I need to create a layout that includes a container_div beneath the body element, both set to 100% height. The header should be 170px tall, followed by a content div that stretches from ...

Incorporating additional text following the creation of an image composite using HTML5

I am facing an issue with positioning two images on a canvas using HTML5. Despite changing the x and y properties, the images remain stuck at the top left corner (0, 0). This is different from how I can position text easily on the canvas. <canvas width ...

Challenge with Making Backgrounds Responsive on Android Chrome

I’m facing an issue with the responsive background on Android Chrome. It displays correctly on PC browsers like Safari, Firefox, and Opera, as well as in Firefox on Android. However, I am encountering a problem with Chrome on Android where it doesn’t a ...

I am having trouble selecting a search suggestion using selenium. The website does not allow me to simply click on submit, it requires me to make a selection

Streamlining the search for temporary apartments has become a priority for me, however, one website's drop-down list requirement is hindering my progress. I must select an option from the dropdown menu before being able to submit my search query, rega ...

CSS - ensure that two elements with display: table-row stay stacked on top of one another

I came across this HTML structure .table { display: table; } .row { display: table-row; } .cell { display: table-cell; text-align: center; padding: 5px; border-right: 1px solid #ddd; border-bottom: 1px solid #ddd; } .sticky { positi ...