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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:16:35+00:00 2026-05-28T02:16:35+00:00

I’ve created a slider which works on a timer along with next/prev arrows. When

  • 0

I’ve created a slider which works on a timer along with next/prev arrows.

When an arrow is clicked I want to stop the auto timer then re-start x-time after the last click. Unfortunately what I have currently seems to que timers so if the arrow is clicked multiple times the auto timer restarts but moves really fast…

I can’t seem to work it out – how to maintain just one setInterval and avoid them building up…

Any help greatly appreciated – code pasted below

    var int = setInterval(back, autoTimerTime);
    //down arrow    
    $('.arrow-down').click(function(){
        if (!$('ul.as-thumbs').is(':animated')) {
            back();
            clearInterval(int);
            clearTimeout(timeout);
            var timeout = setTimeout(function() {
                var int = setInterval(back, autoTimerTime);
            }, 8000);
        }
    });
  • 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-28T02:16:36+00:00Added an answer on May 28, 2026 at 2:16 am

    You have to place the reference to the timout in the common scope of the click handlers, as shown below. When var is used in a new scope, the variable is declared again, in the local scope[1].

    var int = setInterval(back, autoTimerTime);
    var timeout; // This variable is now shared by all $('.arrow-down').click funcs
    //down arrow    
    $('.arrow-down').click(function(){
        if (!$('ul.as-thumbs').is(':animated')) {
            back();
            clearInterval(int);
            clearTimeout(timeout);
            timeout = setTimeout(function() {
                // Removed `var` too
                int = setInterval(back, autoTimerTime);
            }, 8000);
        }
    });
    

    [1]: Illustrated explanation of local/global variables

    In short, variables prefixed by the var keyword are declared again in the local scope. In JavaScript new scope can be created by surrounding a block by function() { .. }.

    When a variable is requested, the engine first looks in the current (local) scope. If the variable is present, this variable is used.
    Otherwise, the parent scope is examined, etc, etc, until the variable is found. If the variable is not found at the top (global scope), the following will happen:

    • In strict mode, a ReferenceError will be thrown.
    • When assigning, foo = 1, the variable will be declared at the global scope

      @Nitpicks: let not taken into account)
    • When reading: A ReferenceError will be thrown.
    var int = 1, timeout = 2, homeless = 3;
    function click() {
        var timeout = 1;
        homeless = 4;
        timeout = function() {
            var int = 2;
        }
    }
    click();
    
    Variables in the global scope:
    - int     (declared using var, inititalized at 1)
    - timeout (declared using var, inititalized at 2)
    - homeless(declared using var, initialized at 3)
    --- New scope of: function click()
      - No declaratation of `int`, so if used, `int` refers to the global `int`
      - Global var: homeless  (assigned 4)
      - Local var: timeout    (declared using var, init at 1)
      - Local var: timeout (assigned anonymou function())
      --- New scope of: function()
        - Local var: int     (declared using var, init at 1)
        - Accessible vars from parent scope: timeout
        - Accessible vars from global scope: homeless, int
          (Note that the global `timeout` var is unreachable, because it
           has been redeclared at the parent scope)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
i want to parse a xhtml file and display in UITableView. what is the

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.