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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:37:18+00:00 2026-05-27T07:37:18+00:00

I have a simple image rotator script that I’m trying to build but I

  • 0

I have a simple image rotator script that I’m trying to build but I am having trouble learning scope as it relates to getting variables into and out of JavaScript functions.

Here is my code:

<script type="text/javascript">

jQuery(document).ready(function($) {


    function indexUp () {

        if (slide_curr == slide_max - 1) {

            slide_curr = slide_max;
            slide_prev = slide_max - 1;
            slide_next = slide_min;

        } else if (slide_curr == slide_max) {

            slide_curr = slide_min;
            slide_prev = slide_max;
            slide_next = slide_min + 1;

        } else {

            slide_curr = slide_next;
            slide_prev = slide_curr - 1;
            slide_next = slide_curr + 1;

        }

    }

    function doTransition () {

        // turn on the display of the next slide
        $(slides[slide_next]).css('display','block');
        // fade the current slide out (to zero opacity)
        $(slides[slide_curr]).fadeOut(600, function() {});

    }

    function printState () {

        var state_str = 'slide_curr='
            + slide_curr
            + '; slide_prev='
            + slide_prev
            + '; slide_next='
            + slide_next
            + '; slide_max='
            + slide_max
            + '; slide_min='
            + slide_min;
        $('#bx_state').html(state_str);

    }

    function doIt () {

        doTransition();
        indexUp();
        printState();

    }

    // variables
    var slides = $('#bx_slider img');
    var slide_min, slide_max, slide_curr, slide_prev, slide_next;
    // initialize the settings
    slide_min = 0;
    slide_max = slides.length - 1;
    slide_curr = 0;
    slide_prev = slide_max;
    slide_next = 1;

    // start it all off when the page loads
    $(slides[slide_curr]).css('display','block');
    timeout = setTimeout(doIt, 3000);


});

</script>

<style type='text/css'>
    #bx_slider img {
            display:none; position:absolute;}
    #bx_slider {
            width:922px; height:530px; margin:100px auto;
            position:relative;}
</style>

<div id="bx_slider">
    <img src="slide1.jpg" />
    <img src="slide2.jpg" />
    <img src="slide3.jpg" />
    <img src="slide4.jpg" />
    <img src="slide5.jpg" />
</div><!-- #bx_slider -->

<div id='bx_state'></div>

I’m trying to get the slide_curr, slide_next, and slide_prev to change each time the script is run and then print those out to the page in the div tag in an effort to see what is going on; however, even that is not working for me.

Here is the script in action: http://www.exit44.com/slider/

Thanks for 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-27T07:37:19+00:00Added an answer on May 27, 2026 at 7:37 am

    I’m guessing here, but perhaps the problem has nothing to do with variable scope. You mention that you want to create a “simple image rotator”. Try changing

    timeout = setTimeout(doIt, 3000);
    

    to

    timeout = setInterval(doIt, 3000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple image upload script that uses SimpleImage.php (http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/) to resize and
I have a simple image-looping script that changes the src of an image. function
I have a simple Button control that contains an Image object as its content.
Situation: I have a simple XML document that contains image information. I need to
I have a simple image inside an HTML form that acts as a button.
I have a simple jQuery image switch that is failing. $('.heart_img').click(function() { var heart_type
I have a JQuery script which acts as a simple image rollover with a
I have a simple image gallery that I've paginated, and I want to to
I am having real trouble referencing a simple image in a jar file. I
I have programmed a simple app that every X minutes checks if an image

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.