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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:44:28+00:00 2026-05-30T06:44:28+00:00

I am making a simple slider that works by changing the src attribute of

  • 0

I am making a simple slider that works by changing the src attribute of an img tag and the attributes of anchor tags. This is what I have come up with so far:

(function($){
    var slides = [
        'http://placehold.it/801x350',
        'http://placehold.it/802x350',
        'http://placehold.it/803x350'
    ],
    titles = [
        'Title 1',
        'Title 2',
        'Title 3'
    ],
    links =  [
        'http://test1.com',
        'http://test2.com',
        'http://test3.com'
    ],
    image = $('#stretch-img'),
    anchor = $('.featured-title>h2>a');

    var interval = setInterval(function() {
        image.attr('src', slides[0]);
        anchor.attr('href', links[0]);
        anchor.html(titles[0]);
    }, 3000);
})(jQuery);

I want the interval to loop through the arrays continuously with a simple fade effect. What can be the best way to do this or any way to do this really, coz I’ve got none.

Thanks!

I appreciate all the help.

  • 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-30T06:44:30+00:00Added an answer on May 30, 2026 at 6:44 am

    To loop through your array you can set a current-position-variable and a variable that saves the length of the array:

    var current = 0,
        length  = slides.length,
        interval = setInterval(function() {
            image.attr('src', slides[current]);
            anchor.attr('href', links[current]).html(titles[current]);
    
            current++;
            if (current >= length) {
                current = 0;
            }
        }, 3000);
    

    Then to fade you can fade-out, change the source, then fade-back-in:

            image.fadeOut(500, function () {
                image.attr('src', slides[current]).fadeIn(500);
                anchor.attr('href', links[current]).html(titles[current]);
    
                current++;
                if (current >= length) {
                    current = 0;
                }
            });
    

    This can lead to the image not quite being loaded when the fadeIn(500) kicks-in, which can be fixed by using an event handler attached to the load event for the image element:

    var image = $('#stretch-img').on('load', function () {
        image.fadeIn(500);
    });
    

    Then you can remove the fadeIn(500) from the interval function since it will fire when the image has loaded. The load event will fire whenever the source of the image changes and the new source finishes loading.

    Note that .on() is new in jQuery 1.7 and is the same as .bind() in this case.

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

Sidebar

Related Questions

Im making a simple wallpaper changer. It works when changing the wallpaper but i
If I'm making a simple grid based game, for example, I might have a
I'm making a simple tool that will get a string of MySQL commands and
I'm making a simple remove link with an onClick event that brings up a
I have read in a book that specifies this : //: C03:SimpleCast.cpp int main()
Im making a simple proof of concept page with jQuery: $('.notclicked').click(function() { $(this).addClass(clicked); $(this).removeClass(notclicked);
I´m making a simple website to display information from XML file that is created
I am making simple application that will take hotel name and price of item,
I'm making a simple class that uses operator<< . It will store two parallel
I'm making a simple drawing program with slides in it and I have an

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.