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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:22:16+00:00 2026-05-31T15:22:16+00:00

I’m using this script from Marco Kuiper and it really works amazingly well. My

  • 0

I’m using this script from Marco Kuiper and it really works amazingly well. My only issue is I don’t want this slideshow to loop. Can anybody help me figure how how to get this script to just run once? I suspect it has something to do with the setInterval function, but I only enough Javascript to play around and not enough to write (although I’m learning slowly). Thanks in advance!

Link to script as well:

http://www.marcofolio.net/webdesign/advanced_jquery_background_image_slideshow.html

     /*
     * Author:      Marco Kuiper (http://www.marcofolio.net/)
     */

     // Speed of the automatic slideshow
     var slideshowSpeed = 7000;

     // Variable to store the images we need to set as background
     // which also includes some text and url's.
     var photos = [ {
    "title" : "Stairs",
    "image" : "dove.jpg",
    "url" : "http://www.sxc.hu/photo/1271909",
    "firstline" : "Imagine a Day of Peace.",
    "secondline" : "",
    "thirdline" : ""
}, {
    "title" : "Office Appartments",
    "image" : "prayer.jpg",
    "url" : "http://www.sxc.hu/photo/1265695",
    "firstline" : "",
    "secondline" : "Imagine a day where the world unites,<br><br> for one purpose",
    "thirdline" : ""
}, {
    "title" : "Mountainbiking",
    "image" : "trees.jpg",
    "url" : "http://www.sxc.hu/photo/1221065",
    "firstline" : "",
    "secondline" : "",
    "thirdline" : "To take a day, to feel what it would be like..."
}, {
    "title" : "Mountains Landscape",
    "image" : "ocean.jpg",
    "url" : "http://www.sxc.hu/photo/1271915",
    "firstline" : "...to have a world at",
    "secondline" : "",
    "thirdline" : ""
}
     ];



jQuery(document).ready(function() {

 jQuery("#headerimgs").css({"display":"none"}); 
jQuery("#headerimgs").fadeIn(2000); 

// Backwards navigation
jQuery("#back").click(function() {
    stopAnimation();
    navigate("back");
});

// Forward navigation
jQuery("#next").click(function() {
    stopAnimation();
    navigate("next");
});

var interval;
jQuery("#control").toggle(function(){
    stopAnimation();
}, function() {
    // Change the background image to "pause"
    jQuery(this).css({ "background-image" : "url(images/btn_pause.png)" });

    // Show the next image
    navigate("next");

    // Start playing the animation
    interval = setInterval(function() {
        navigate("next");
    }, slideshowSpeed);
});


var activeContainer = 1;    
var currentImg = 0;
var animating = false;
var navigate = function(direction) {
    // Check if no animation is running. If it is, prevent the action
    if(animating) {
        return;
    }

    // Check which current image we need to show
    if(direction == "next") {
        currentImg++;
        if(currentImg == photos.length + 1) {
            currentImg = 1;
        }
    } else {
        currentImg--;
        if(currentImg == 0) {
            currentImg = photos.length;
        }
    }

    // Check which container we need to use
    var currentContainer = activeContainer;
    if(activeContainer == 1) {
        activeContainer = 2;
    } else {
        activeContainer = 1;
    }

    showImage(photos[currentImg - 1], currentContainer, activeContainer);

};

var currentZindex = -1;
var showImage = function(photoObject, currentContainer, activeContainer) {
    animating = true;

    // Make sure the new container is always on the background
    currentZindex--;

    // Set the background image of the new active container
    jQuery("#headerimg" + activeContainer).css({
        "background-image" : "url(images/" + photoObject.image + ")",
        "display" : "block",
        "z-index" : currentZindex
    });

     // Hide the header text
    jQuery("#headertxt").css({"display" : "none"});

    // Set the new header text
    jQuery("#firstline").html(photoObject.firstline);
    jQuery("#secondline")
        .attr("href", photoObject.url)
        .html(photoObject.secondline);
    jQuery("#thirdline")
        .attr("href", photoObject.url)
        .html(photoObject.thirdline);
    jQuery("#pictureduri")
        .attr("href", photoObject.url)
        .html(photoObject.title);



    // Fade out the current container
    // and display the header text when animation is complete
    jQuery("#headerimg" + currentContainer).fadeOut(2000,function() {

        setTimeout(function() {
            jQuery("#headertxt").fadeOut({duration:1000});
            jQuery("#headertxt").fadeIn({duration:1000});
            animating = false;
        }, 300);
    });
};

var stopAnimation = function() {
    // Change the background image to "play"
    jQuery("#control").css({ "background-image" : "url(images/btn_play.png)"          });

    // Clear the interval
    clearInterval(interval);
};

// We should statically set the first image
navigate("next");

// Start playing the animation
interval = setInterval(function() {
    navigate("next");
}, slideshowSpeed);
     });
  • 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-31T15:22:17+00:00Added an answer on May 31, 2026 at 3:22 pm

    If you want it to go once through the images and then stop, you can change the navigation function like this (adding the lines with a comment by them). This new code looks for the cases where the slide index was going to wrap around and when it sees that, it stops the interval and doesn’t show the new slide – effectively stopping the slideshow.

    var navigate = function(direction) {
        // Check if no animation is running. If it is, prevent the action
        if(animating) {
            return;
        }
    
        // Check which current image we need to show
        if(direction == "next") {
            currentImg++;
            if(currentImg == photos.length + 1) {
                currentImg = 1;
                stopAnimation();                     // add this
                return;                              // add this
            }
        } else {
            currentImg--;
            if(currentImg == 0) {
                currentImg = photos.length;
                stopAnimation();                     // add this
                return;                              // add this
            }
        }
    
        // Check which container we need to use
        var currentContainer = activeContainer;
        if(activeContainer == 1) {
            activeContainer = 2;
        } else {
            activeContainer = 1;
        }
    
        showImage(photos[currentImg - 1], currentContainer, activeContainer);
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of 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.