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 6865755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:05:37+00:00 2026-05-27T03:05:37+00:00

I’m trying to make an infinitely rotating imagereel with jQuery. This imagereel shifts between

  • 0

I’m trying to make an infinitely rotating imagereel with jQuery. This imagereel shifts between images with an interval of 5000 milliseconds, then fading out the ‘old’ image and fading in the ‘new’ image. The image to be displayed has a style-attribute for “display:inline”.

The code can be found below:

function switchImage(){

    var selector = $('#fotoreel img[style="display: inline; "]');
    var nextOne = $(selector).next();
    if($(nextOne).length == 0)
    {
        var nextOne = $('#fotoreel img:first');
    }
    $(selector).fadeOut('normal',function(){
        $(nextOne).fadeIn('normal');
    });
    var t = setTimeout("switchImage()",5000);
}

$(document).ready(function(){
    setTimeout("switchImage()",5000);
});

The problem is that it works fine in Chrome, but in Firefox and in Opera it only shifts image one time. In IE it’s worse; there it doesn’t work at all.

Do you guys know a better way of infinitely looping with javascript? Now I use setTimeout() to call the function again, but that doesn’t seem to work.

EDIT

Okay, thank you everyone! Such fast responds, awesome!

The solution that I used was the one of adding a class and searching for that instead of for the style. The display:inline didn’t appear to be a problem, as it worked out, but all the browsers appeared to implement the jQuery fadeIn() function differently.

I namely wanted to filter EXACTLY on “display: inline ;”, because the spaces were added in Chrome, but not in IE, FF or Opera. So that means the style attribute wasn’t accurately at all to filter with. Stupid me! 🙂

I made sure that a class was added to the image that is showed currently, and find the next one by filtering on that class. Now it works like a charm.

Thank you all for your answers, I love this place! 😀

  • 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-05-27T03:05:37+00:00Added an answer on May 27, 2026 at 3:05 am

    It’s probably going to work better if you explicitly mark images with a class:

    function switchImage(){
    
      var selector = $('#fotoreel img.current');
      var nextOne = $(selector).length ? $(selector).next();
      if($(nextOne).length == 0)
      {
        var nextOne = $('#fotoreel img:first');
      }
      $(selector).fadeOut('normal',function() {
        $(selector).removeClass('current');
        $(nextOne).addClass('current').fadeIn('normal');
      });
      setTimeout(switchImage, 5000);
    }
    
    $(document).ready(function(){
      $('#fortoreel img:last-child').addClass('current');
      setTimeout(switchImage,5000);
    });
    

    Note also that in my calls to “setTimeout()” I pass a direct reference to the function instead of a string version of the code to call it.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.