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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:26:03+00:00 2026-05-15T01:26:03+00:00

This is my first post, so please forgive me if this question has been

  • 0

This is my first post, so please forgive me if this question has been asked a million times. I’m a self professed jQuery hack and I need a little guidance on taking this script I found and adapting it to my needs.

Anyway, what I’m making is an image slide show with navigation. The script I found does this, but does not automatically cycle through the images. I’m using jQuery 1.3.2 and would rather stick with that than using the newer library. I would also prefer to edit what is already here rather than start from scratch.

Anywho, here’s the html:

 <div id="slideshow-container"> 
        <div id="myslide">
            <div class="cover">
                <div class="mystuff">
                    <img alt="&nbsp;" src="image1.jpg" />
                </div>
                <div class="mystuff">
                    <img alt="&nbsp;" src="image2.jpg" />
                </div>
                <div class="mystuff">
                    <img alt="&nbsp;" src="image3.jpg" />           
                </div>
                <div class="mystuff">
                    <img alt="&nbsp;" src="image4.jpg" />           
                </div>

            </div> <!-- end of div cover -->
        </div>  <!-- end of div myslide -->
    <div id="button">
        <a class="button1 active" rel="1" href="#">1</a>
        <a class="button2" rel="2" href="#">2</a>
        <a class="button3" rel="3" href="#">3</a>
        <a class="button4" rel="4" href="#">4</a>
    </div> <!-- end of div button--> 
</div><!-- end of slideshow-container -->

And here’s the jQuery:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/JavaScript">
    $(document).ready(function (){
        $('#button a').click(function(){
            var integer = $(this).attr('rel');
            $('#myslide .cover').css({left:-820*(parseInt(integer)-1)}).hide().fadeIn(); /*----- Width of div #mystuff (here 820) ------ */
            $('#button a').each(function(){
            $(this).removeClass('active');
                if($(this).hasClass('button'+integer)){
                    $(this).addClass('active')}
            });
        }); 
    });
    </script>

Here’s where I got the script: http://www.webdeveloperjuice.com/2010/04/07/create-lightweight-jquery-fade-manual-slideshow/

Again, if this question is too basic for this site please let me know and possibly provide a reference link or two. Thanks a ton!

Edit:
I actually tried Matt’s suggestion earlier but was unclear on the syntax of using setInterval with what I was working with. Here is the code that I was working with earlier, that isolates the image change. When this is loaded, the initial image loads with a fade animation but nothing else happens.

    <script type="text/JavaScript">
    $(document).ready(function(){
        var integer = $(this).attr('rel');
        $('#myslide .cover').css({left:-820*(parseInt(integer)-1)}).hide().fadeIn(); /*----- Width of div #mystuff (here 820) ------ */
    });
    </script>

Obviously this doesn’t include setInterval() but that’s because, frankly, I’m clueless about the syntax and application of setInterval().

Solution provided by nate and adapted slightly:

   <script>
    // Consider calculating these values instead of hard-coding them.
    // The "currrentFrame" is the id with the "active" class,
    // and the totalFrames could be counted with jQuery.   
    var currentFrame = 1; 
    var totalFrames = 4;
    var timeoutId;

    $(document).ready(function (){
        // Handle the numbered button clicks
        $('#button a').click(function(){showFrame($(this).attr('rel'));
        });
        //automatically handle slide rotation
        $('document').ready(function(){getNextFrame($(this).attr('rel'));
        setInterval("getNextFrame()",3000); // time in milliseconds
        });
    });

    // I put the contents of the original click handler here
    // so that it could be called by both the button and the timer.
    function showFrame(integer){           
        $('#myslide .cover').css({left:-820*(parseInt(integer)-1)}).hide().fadeIn(); 
        $('#button a').each(function(){
            $(this).removeClass('active');
            if($(this).hasClass('button'+integer)){
                $(this).addClass('active')}
        });
    // storing the current frame globally
    currentFrame = integer;
    }; 

    // determine the next frame using the 
    // currentFrame global. Again, a better way
    // to do this could be to calculate the current
    // frame with jquery...
    function getNextFrame() {
        currentFrame = parseInt(currentFrame);
        currentFrame++;
        if(currentFrame > totalFrames)
            currentFrame = 1;
        showFrame(currentFrame);


    }
    </script>
  • 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-15T01:26:04+00:00Added an answer on May 15, 2026 at 1:26 am

    You’ve got two problems to solve here:

    1. Create a function that can determine the next frame.
    2. Call that function on a given interval.

    Split out the code that displayes the current frame as its own function, as in showFrame().

    Then make a function that determines which frame to call next, as in getNextFrame().

    Finally, add buttons that call setInterval() and clearInterval() as needed, as in toggleSlideShow().

    But once you get this working, make another attempt at Cycle or another such plugin.

        <script>
        // Consider calculating these values instead of hard-coding them.
        // The "currrentFrame" is the id with the "active" class,
        // and the totalFrames could be counted with jQuery.   
        var currentFrame = 1; 
        var totalFrames = 4;
        var timeoutId;
    
        $(document).ready(function (){
            // Handle the numbered button clicks
            $('#button a').click(function(){showFrame($(this).attr('rel'));
            });
            //handle the start/stop clicks
            $('#controlButton a').click(function(){toggleSlideShow($(this).attr('rel'));
            });
        });
    
        // I put the contents of the original click handler here
        // so that it could be called by both the button and the timer.
        function showFrame(integer){           
            $('#myslide .cover').css({left:-820*(parseInt(integer)-1)}).hide().fadeIn(); 
            $('#button a').each(function(){
                $(this).removeClass('active');
                if($(this).hasClass('button'+integer)){
                    $(this).addClass('active')}
            });
            // storing the current frame globally
            currentFrame = integer;
            }; 
    
        // determine the next frame using the 
        // currentFrame global. Again, a better way
        // to do this could be to calculate the current
        // frame with jquery...
        function getNextFrame() {
            currentFrame = parseInt(currentFrame);
            currentFrame++;
            if(currentFrame > totalFrames)
                currentFrame = 1;
            showFrame(currentFrame);
        }
    
        // Start and stop the slide show.
        // The important part here are the setInterval and
        // clearInterval functions.
        function toggleSlideShow(state){
            // using the same technique for the start
            // and stop buttons
            $('#controlButton a').each(function(){
                $(this).removeClass('active');
                if($(this).hasClass('button'+state)){
                    $(this).addClass('active')}
                    });
                if(state == "Start") {
                    //Store the timeoutId for later...
                    timeoutId = setInterval("getNextFrame()",1000); // time in milliseconds
                    }
                else {
                    //...so it can be used to stop the show.
                    clearInterval(timeoutId);
                }
         }
        </script>
    

    Here is the source for the start/stop buttons I added. You can put this where you like–I inserted it after the button div.

        <div id="controlButton">
            <a class="buttonStart" rel="Start" href="#">Start</a>
            <a class="buttonStop" rel="Stop" href="#">Stop</a>
        </div>
    

    I also defined .buttonStart,.buttonStop in the CSS file.

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

Sidebar

Related Questions

This is my first post here and I wanted to get some input from
This is my first post and I'm quite a novice on C++ and compiling
Well, this is my first post here and really enjoying the site. I have
this is my first question to stackoverflow so here it goes... I use cruise
This is my first time attempting to call an ASP.NET page method from jQuery.
this is my first question here so I hope I can articulate it well
problem euler #5 i found the solution but i don't know why this first
This is my first experience using the Zend Framework. I am attempting to follow
This is my first time using joomla. I don't know if I'm using the
This is my first crack at a method that is run periodically during 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.