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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:49:27+00:00 2026-06-05T19:49:27+00:00

I have a gallery that doesnt work properly with setTimeout. I need to make

  • 0

I have a gallery that doesnt work properly with setTimeout.
I need to make the gallery change a photo every few sec. but if I press on the indicator, then I want it to change it manually.

this is my js file :

var arrayPic = ["/img/gallery/gal1.jpg", 
                "/img/gallery/gal2.jpg", 
                "/img/gallery/gal3.jpg", 
                "/img/gallery/gal4.jpg", 
                "/img/gallery/gal5.jpg", 
                "/img/gallery/gal6.jpg"];
var counter = 0;
var waitTime = 5000;
var transitionTime = 500;
var t;
var time_is_on = 0;

$(document).ready(function () {


    t = setTimeout(function() {

        changeThisPhoto();
        changeIndicator();

    }, 1000);

    $(".countrydd").ykDropdown();
    $(".subjectdd").ykDropdown();

});


function stopTime() {

    clearTimeout(t);
    time_is_on = 0;
}


function changeDefaultIndicator() {

    console.log($("li.active"));
    var thisChild = ($("li.active").index(this)) + 1;

    for (var i = 0; i < arrayPic.length; i++) {
        $("#indi" + i).removeClass();
    }

    $("#indi" + thisChild).addClass("active");



}

function changeIndicator() {

    $(".indicatorslist li").bind("click", function () {

        var thisChild = ($(".indicatorslist li").index(this)) + 1;

        for (var i = 0; i < arrayPic.length; i++) {
            $("#indi" + i).removeClass();
        }

        $("#indi" + thisChild).addClass("active");

        changeThisPhoto(thisChild);

    })

 }


function animatePhotoOut() {

    $(".backgroundImage").animate({

        opacity: 1

    }, transitionTime, function () {
        $(".backgroundImage").delay(waitTime);
        changeThisPhoto();

    })

}

function changeThisPhoto(child) {

    var stepper = 0;

    if (!child) {
        child = -1;
    }


    $(".backgroundImage").stop().animate({
        opacity: 0
    }, transitionTime, function () {


        if (counter == 5) {
            counter = 0;
        } else {
            counter++;
        }

        if (child = -1) {
            stepper = counter;
        }
        else {
            stepper = child;
        }

        $(".backgroundImage").css("background-image", 
                                  "url('" + arrayPic[stepper] + "')");

        changeDefaultIndicator();
        animatePhotoOut();
    })
}

it works beautifully when I click the indicator, but won’t work with the setTimeout() function… probably…

  • 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-05T19:49:28+00:00Added an answer on June 5, 2026 at 7:49 pm

    The setTimeout will only run the change once. Use setInterval instead.

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

Sidebar

Related Questions

I have a photo gallery I would like that every time a user does
I have photo gallery code that does image re-sizing and thumbnail creation. I use
I have a PHP photo gallery that reads the GPS coordinates from images. I'd
So I have a gallery , that I need to have the main image
I have this gallery that uses that ipad / iphone swipe from http://www.simplesli.de but
I have a gallery that's loaded via a BaseAdapter . This works fine. I
I have an image gallery that I created by reading the contents inside a
I have an image gallery app that has a slider to control the width
I have custom gallery. Gallery represents items that are frame layout. There are one
Does anyone have a suggestions for a superb cool image gallery that I can

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.