Slideshow with Jquery featuring image transitions from left to right and elegant fade-in effects

I am trying to create a unique slideshow effect with 6 graphics. The first two graphics should slide from left to right, the third graphic should fade in and stick, and then the remaining graphics should slide from left to right. I have been able to implement individual effects in my slideshow code, but I am struggling to combine sliding and fading animations. How can I achieve this blend of effects? Below is the current code snippet:

<div id='slider_container'>
    <div id="slides">
        <img src='images/Team-Up-wTag_CMYK_Over-White.jpg' />
        <img src='images/Together-all-3-01.jpg' />
        <img src='images/One-Team-One-Focus-RESIZED.jpg' />
        <img src='images/Orlando_Seaworld_ExteriorSeaworldView.jpg' />
        <img src='images/DSC_1465.JPG' />
        <img src='images/DSC_1470.JPG' />
    </div>
</div>

<script type="text/javascript"> 
    $(window).load(function() {
        var slideContainer = $('#slider_container'), slidesHolder = $(slideContainer).children(),  slideWidth = slideContainer.width(), slidePos = 0, slides = $(slidesHolder).children(), slideTotal = slides.length, currentSlide = 0, delay = 3000, slideTime = 800;

        $(slideContainer).css({
            'overflow': 'hidden',
            'position': 'relative'
        });

        $(slidesHolder).css({
            'position': 'absolute'
        });

        for (var i = 0; i < slides.length; i++) {
            $(slides[i]).css({
                'position': 'absolute',
                'top': '0',
                'left': slidePos + 'px'
            });
            slidePos = slidePos + slideWidth;
        }

        $(slidesHolder).css('width', slidePos + slideWidth);

        $(slides).first().clone().css({
            'left': slidePos  + 'px'
        }).appendTo(slidesHolder);

        function animate() {
            $(slidesHolder).delay(delay).animate({
                left: '-=' + slideWidth
            }, slideTime, function() {
                if (currentSlide < slideTotal - 1) {
                    currentSlide++;
                    animate();
                } else {
                    $(slidesHolder).css({
                        'left': 0
                    });
                    currentSlide = 0;
                    animate();
                }
            });
        }
        animate();
    });
</script>

Answer №1

After spending some time on this task following your initial post, I believe I've managed to come up with a rough draft.

Among my numerous weaknesses, one that stands out is my struggle with the .animate function and understanding how animations can override each other. Fortunately, I was able to discover some useful code snippets HERE and tweak them to suit my needs.

You can view this FIDDLE showcasing the identical animation of four images.

On the other hand, this FIDDLE provides an option to stop a specific image by setting "distance = 0".

Javascript code snippet with "stop":

var $imgs = $('img');
var current = 0;
distance = 75;
animate($imgs[current]);
function animate(element)
{
  $(element).animate(
                     {
                      opacity: '1',
                      left: '+=' + distance
                      }, 
                      2000,
                      function() {
                                 $(element).animate(
                                                    {
                                                     opacity: '0',
                                                     left: '+=' + distance
                                                     }, 
                                                     2000,
                                  function(){
                                             if (current < $imgs.length-1)
                                               {
                                                if (current == 1)
                                                  {distance = 0;}
                                                    else
                                                  {distance = 75;}
                                                ++current;
                                                animate($imgs[current]);
                                                } 
                                             }
                                                     );
                                  }
                       );
}

This experience taught me the importance of executing any complex animation manipulation within the final function call to avoid conflicts between animations.

A stimulating exercise indeed!

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

Is HTML-React-Parser giving back an object instead of a string?

Currently, I am attempting to convert basic HTML code into JSX format using HTML-React-Parser. To achieve this, I have included the script in my HTML document as shown below: <script src="https://unpkg.com/html-react-parser@latest/dist/html-react- ...

Creating round corners for images with jQuery

To achieve rounded corners on multiple blocks using a single image above, I am opting for the use of images instead of plugins for maximum compatibility. This involves creating wrappers around the blocks to apply the corner images: <div class="wrapper- ...

Differences between Creating and Updating Objects in JavaScript

When working with JavaScript, it is important to consider the best practices for performance optimization. Take a look at these two examples: Example 1: var x = {}; x.a = 10; Example 2: var x = {}; x = {a: 10}; Are there any noticeable differences in ...

Trouble persisting values with Heroku due to variable issues

Here is a concise example: let value = null; const getValues = () => { fetch('/third-party-api') .then(res => res.json()) .then(data => { value = data; }) } getValues(); app.get("/values", async (req, res) ...

Using Angular to send data to a WCF JSON endpoint

I've been trying to send a request to a WCF JSON service endpoint from Angular, but I haven't had any luck so far. The service has been tested through other methods and is functioning properly for the specified URL. When checking with Firebug, I ...

Exploring JSON data with multiple nested layers of iteration

I'm currently working on a project that involves parsing through a JSON file with a complex structure. I've been attempting to extract a link to an image within the JSON data, but my current approach is resulting in an error. Below you'll fi ...

Is there a way to switch out underscores for spaces in autocomplete suggestions?

I am currently using jquery-ui to develop a search dropdown feature, but I would like the results in the dropdown to display spaces instead of underscores. Unfortunately, using .replace on the source code does not seem to be effective. Below is the snippe ...

Child component in VueJs is undergoing a situation where the variable is found to be

Whenever an event is triggered, a function is called to populate a variable and open a modal from a child component. However, in the modal, the new variable appears empty initially. If I close and then reopen the modal, the data finally loads. I have atte ...

React fetch request does not reach the Express router's index route

Having some experience with Express, I am relatively new to React. My React app is connected to an Express server, but I am struggling to get fetch('/') in my main React App component to hit the index route in Express. In my Express app, I have s ...

Troubleshooting Vue: Why is my component not visible when using v-form and v-text-field components in Vuetify?

Attempting to implement the v-form and v-text-field components from the Vuetify node package. <template> <v-form> <v-text-field label="Test" type="foo"></v-text-field> <v-text-field label="bar&q ...

Creating a dynamic table in HTML using PHP

I seem to be facing an issue with my PHP code. Below is the snippet of the code I am working with: <?php $s=(" SELECT * FROM my_tbl"); $W=mysql_query($s); ?> <table> <tr> <td> <center><s ...

"Troubleshoot: jQuery UI accordion not functioning properly in response to

I've encountered an issue with the accordion functionality while working with dynamic data. To address this, I'm incorporating JavaScript to generate <div> and <h3> tags for the accordion. Here is the code snippet I am using: $(&ap ...

Expanding Bootstrap 5 dropdown menu dynamically using Javascript

Is there a method to achieve this goal? I am currently attempting to implement a dropdown menu that dynamically populates with year numbers starting from the current year. Unfortunately, the solutions I have come across only work with native HTML and not B ...

JavaScript functions flawlessly when run on a local machine, but encounters issues when transferred to a server

My JavaScript code is functioning perfectly on my local machine, but as soon as I upload it to my web server, it stops working. The website in question is www.turnbulldesigns.co.uk if you want to take a look. I have transferred the complete folder structu ...

Replace the instances of "foo" with "bar" in the phrases "foo bar" and "bar foo."

Using a regular expression, I am able to locate specific words and then manipulate them in some way. For example: I want to surround all the words I find with <strong> tags: $string = 'Hello, there is foo, after there is bar but now I need fo ...

What could be causing my NextAuthJS discord login to function in the test environment but fail to deploy in production on NextJS 13?

After attempting to deploy my NextJS application on Vercel, I encountered a problem with the AuthJS sign-in model. While running the program using npm run dev, everything works smoothly and I can log in to my Discord account linked to the developer portal& ...

Problem encountered when attempting to set and retain default values in a PHP select box

<form name="search" method="post" > Seach for: <input type="text" name="find" value="<?php echo (isset($_POST['find']) ? $_POST['find'] : ''); ?>" /> in <Select NAME="field"> <Option VALUE="catego ...

Question about the origin of style sheet source files [*.css?ver=]

Can you explain the purpose of appending a query string to the end of a style sheet? I frequently come across examples like this: some-stylesheet.css?ver=1.2.3 Appreciate your insights. ...

The steps to developing a jQuery counter

Currently, I'm attempting to implement a counter using jQuery, but unfortunately it's not functioning as intended. The setup involves 3 inputs - one number input and two buttons. Here is an overview of my HTML structure: <html> <he ...

unable to apply angular measurement inside quotation marks

What is the reason for this issue: <ul class="dropdown-menu"> <li ng-repeat="choice in dropDownItems"> <a class="btn" ng-click="mnuClick('{{choice}}')">{{choice}}</a> </li> </ul> However, this code wo ...