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

  • Home
  • SEARCH
  • 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 7938473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:49:22+00:00 2026-06-03T22:49:22+00:00

i can’t manage to make this work : in my gallery, if i click

  • 0

i can’t manage to make this work : in my gallery, if i click on a “bullet” (when setInterval is already running) there is a bug, example :

when i let the gallery running : edit: the click on bullets did not work properly :

var current = 0;
/* click on BULLETS : i think the problem is in this function */
pts.live('click', function () {
        var index = $(this).index();

        clearInterval(timer);
        current = index-1;
        timer = setInterval(function() { showImage(current) },2000); 

        return false;
    });

EDIT : thanks Gavriel, it seems better with addClass indeed! but i can’t manage to fix the click on the bullets : when i click on a bullet, i would like to “stop” the interval and go directly to the image i clicked on. Is it possible? when i try it (please see below), the “current” image stays as is, it stays for 1-2 seconds, then starts again the interval as if nothing happened… would you have any idea?

/* click on BULLETS :  */
pts.live('click', function () {
        var index = $(this).index();

        clearInterval(timer);

        li.removeClass('next');
        li.eq(index).addClass('next');
        showImage();

        timer = setInterval(function() { nextImage() }, 1000);

        return false;

    });

//TIMER
var timer = setInterval(function() { nextImage() }, 1000);
li.eq(0).addClass('next');

function nextImage(){
    var index = $('#contG').find('li:.next').index();
    $('#contG').find('li:.next').removeClass('next').addClass('current');

    /*design bullet */
    var pts_li = $("#points").find('ul').find('li');
        pts_li.removeClass('activ');

    /* limit */
    var total = li.length; //3

    if (index+1>total-1) {
        index = 0;
    } else {
        index = index+1;
    }

    li.eq(index).removeClass('current').addClass('next');
    pts_li.eq(index).addClass('activ');

    showImage();
}


/* SHOWIMAGE */
function showImage(){
    //clearInterval(timer);
    $('#contG').find('li:.next').fadeIn("slow");//FADEIN
    $('#contG').find('li:.current').fadeOut("slow");//FADEOUT
}

EDIT N°2 : FINAL COMBAT

ok i finally found out how to solve this… 🙂 Thanks Firebug :

here’s the code :

pts.live('click', function () {
        var index = $(this).index();

        clearInterval(timer);

        $('#contG').find('li:.next').removeClass('next').addClass('current');

        li.eq(index).removeClass('current').addClass('next');

        showImage();
        timer = setInterval(function() { nextImage() }, 2500);

        return false;
    });

Thanks a lot

  • 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-03T22:49:23+00:00Added an answer on June 3, 2026 at 10:49 pm

    Your problem is the usage of the global current variable. Start using closures:

    (function(c){
        timer = setInterval(function() { showImage(c) },2000);
    })(current);
    

    this way at the moment of the click you’ll pass current to the function, and 2 seconds later you’ll pass THAT value to showImage and not current’v value whatever it may be 2 seconds later.

    However trying to understand what you want to do… I think the better way would be something like this:

    Instead of doing fade to an element that you “calculate” by the value of current, I would try to use classes to “sign” the “current” element: $(this).addClass(“current”) or something like that, and in the fade I would use $(‘#contG’).find(‘li:.current’).fadeOut(“slow”, function(){$(this).removeClass(“current”)});

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

Sidebar

Related Questions

Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
Can someone help me with this scenario? *There is a button, which when tapped,
Can anyone point me towards an example or tutorial for this? I basically want
Can anyone help me trying to find out why this doesn't work. The brushes
Can a Rails class name contain numbers? For example: class Test123 end Is this
Can anyone explain to me why this program: for(float i = -1; i <
I have a jquery bug and I've been looking for hours now, I can't
Can anyone give me an example of how to return the following json simply
Can I run this in a Windows command prompt like I can run it
Can anybody help me? What should be the datatype for this type -07:00:00 of

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.