Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8633877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:34:41+00:00 2026-06-12T09:34:41+00:00

Noob in jQuery. I’m trying to cycle through an image gallery with the goal

  • 0

Noob in jQuery.

I’m trying to cycle through an image gallery with the goal of having the images fade in and fade out.

Here is my JSFiddle
By clicking on #gallery each image fadeTo(arg1) and then fadeTo(args2).
But I want them to go one by one.
Perhaps a delay should be added to the chain?

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:34:42+00:00Added an answer on June 12, 2026 at 9:34 am

    jQuery animations (as most things on javascript) are asynchronous, which means that the function calls return before the action has finished. In a sense, you can think of each iteration of your $('img').each loop as following:

    • jQuery calls your function with this bound to one img element
    • Your function calls fade on $(this)
    • jQuery then asks the browser to schedule an animation to be run
    • Your function returns

    Then, after all your iterations have ended the browser will start to make the animations happen on the screen, all at the same time (since all of them were scheduled).

    To create a sequential behavior, you can give the fade function a callback:

    $('#gallery').click(function(evt) {
      var remainingImages = $("img").toArray();
    
      var processNext = function() {
        var image = remainingImages.shift();
        if(!image) return;
    
        // Add the next iteration as a callback to the animation
        $(image).fadeTo(500, .3).fadeTo(250, 1, processNext);
      };
    
      processNext();
    });
    

    Then, instead of scheduling all animations at once, what happens is something like this:

    • All the current img elements are stored in the remainingImages array
    • The processNext function is called, which removes the first image from the array
    • The function calls fade on the $(image), providing a function (that happens to be itself) that should be called after the animation is finished
    • jQuery schedules the animation with the browser, and tells it to execute the function afterwards
    • After the animation finishes, the next iteration is executed

    Updated jsFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im a jquery noob. I needed a script that would swap out images or
(jQuery noob here) Im trying to write a script which when I write <input
javascript noob trying to figure something out. I saw a script located here: Using
Greetings from some noob trying to learn JQuery, I am attempting to make it
noob here still experimenting with templates. Trying to write a message processing class template
Noob dumb question, no doubt -- but here it is: Trying to tutorialize myself
I've just been learning some jQUery to get a basic image gallery going on
I am a Jquery noob. I and am trying to create an accordion menu.
I'm quite a noob at Jquery but I'm trying to set a variable based
Javascript/JQuery noob here, so apologies. I'm using .ajax to get a JSON object then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.