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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:21:35+00:00 2026-06-01T02:21:35+00:00

Disclaimer: I am trying to learn javascript. I am not a clever man. So,

  • 0

Disclaimer: I am trying to learn javascript. I am not a clever man.

So, I made a Jquery image slider. And I was proud. It works. It loads images, and it displays them one-after-another, day-in, day-out. Life was good.

Then I wanted to add navigation to the slider, and darkness fell upon my little kingdom.

When I click on one of the buttons, I call my LoadSlide function passing on the appropriate index LoadSlide(NewIndex). And then it runs the function, but it also continues running the function with the standard LoadSlide(index+1) argument. So without clicking any buttons it runs like so:

slide1 -> (6500ms) -> slide2 -> (6500ms) -> slide3 -> (6500ms) -> slide1 ...

And then I click a button (slide 2), and another loop starts in parallel:

slide1 -> (6500ms) -> slide2 -> (6500ms) -> slide3 -> (6500ms) -> slide1 ...
   [click] slide2 -> (6500ms) -> slide3 -> (6500ms) -> slide1 -> (6500ms)...

Please advise me, keepers of the lore. Thou shall enjoy many maidens and endless measures of ale, if this dragon is slain.

Pitiful code is here: http://jsfiddle.net/V6svT/2/

  • 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-01T02:21:36+00:00Added an answer on June 1, 2026 at 2:21 am

    The issue you are having is the synchronisation between the animation time and the click triger.
    Also you are not cancelling the next scheduled action when a user click on the button.
    supose we are on slide 2 meaning there is already a timer that is supossed to show slide 3, when i click on button 1 the first timer will keep runig to show slide 3 and another timer will be created to show slide 1. I solve this by holding the timer and clearing it.

    Another issue is that in your adnimation: fadeIn callback you are adding the click lisiner for button which I think will add many listiners so when you click twice you will have the same listner attached twice therefore called twice when trigered.
    Here is my correction works on my side . might have other issues .
    Bear in ming the timing between click and transition. for instance if you set fadeIn time to the same time of setTimeout you will have the same issue.

    $(function () {
    //edit
    var timer='undefined';
    
    var slides = new Array();
        slides[0] = 'http://i.imgur.com/UwRVo.png';
        slides[1] = 'http://i.imgur.com/wv08B.png';
        slides[2] = 'http://i.imgur.com/MlUbx.png'; 
    
       var max = $(slides).length;
    
    var isBottom = false;
    
    makeSlideBtns(max);
    
    if(max>0) 
    {
        LoadSlide(0,max);
    
    }
    
    function LoadSlide(index,max) {
         clearTimeout(timer);
         if(index<max)
            {
                var el0 = $("#slidebottom");
                var el1 = $("#slideover");
                var sbtn = $("#slidebtns li")[index];
                var img = new Image();
                 $(sbtn).css('background-color', '#000'); 
    
                $(img).load(function () {
                    $(this).css('display','none');
                    if(isBottom == true)
                    { 
                        $(el1).html(this);
                        $(el1).css('z-index', '3');
                        $(el0).css('z-index', '2');
                        console.log("el1 " + index);
    
                    } else {
                        $(el0).html(this);
                        $(el1).css('z-index', '2');
                        $(el0).css('z-index', '3');
                        console.log("el0 " + index);
    
                    }
                    isBottom = !isBottom;
    
                    function nextSlide () {                                                                      
                                    LoadSlide(index+1,max);
                                    console.log("sbtn: " + sbtn);
                                    $(sbtn).css('background-color', '#fff');
                    };
    
                    $(this).fadeIn(2000,function() {
                            timer=setTimeout(nextSlide, 5000);     
                    });
    
    
                }).error(function () {             
                    LoadSlide(index+1,max);
                }).attr('src', slides[index]);  
    
            } else {
                LoadSlide(0,max)
            }
    }
    
    function makeSlideBtns (max) {
    
        for(i=0; i<max; i++) {
            var num = i + 1;
            $("#slidebtns").append('<li><a>' + num + '</a></li>');
        }
    };
    
    //add this in your loop will add more as you click
    $("#slidebtns li").click(function () { 
         $("#slidebtns li").css('background-color', '#fff');                                               
         var i=$(this).index();             
          LoadSlide(i,max);
          return false;
      });
    

    });​

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

Sidebar

Related Questions

Disclaimer: I'm trying to learn proper OO programming/design, so I'm pretty new to this
Disclaimer: I'm not actually trying to make one I'm just curious as to how
Just for the disclaimer, I'm not trying to win the prize in Android Developer
DISCLAIMER : I am still a Rails/Cucumber newbie but I am trying to learn.
Disclaimer: I am new to jQuery. I am trying to implement a fadeOut effect
I'm trying to shift a portion of an image, currently using g.copyArea(). It works
Disclaimer : Bluetooth novice question ahead. I'm not trying to troll you with inaccurate
Disclaimer: the following is a sin against XML. That's why I'm trying to change
Disclaimer: This is my first time writing unit tests...be gentle! :) I am trying
Disclaimer: I am a beginner and it is showing. I am trying to follow

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.