Newtt
Newtt

Reputation: 6200

Pause JS slideshow after X slides

I'm trying to play around with a JS plugin I found on Codrops:

http://tympanus.net/codrops/2013/04/17/background-slideshow/

I'm trying to get the slideshow to auto stop after X images. In my case 2 or 3. From what I understood of Mary Lou's code, the function to determine pause/play/next slide is here:

function d(q) {
    var p = g.eq(h);
    console.log('abc');
    if (q === "next") {
        h = h < n - 1 ? ++h : 0
    } else {
        if (q === "prev") {
            h = h > 0 ? --h : n - 1
        }
    }
    var o = g.eq(h);
    p.css("opacity", 0);
    o.css("opacity", 1)
}

This JS is found here:

http://tympanus.net/Blueprints/BackgroundSlideshow/js/cbpBGSlideshow.js

What I've tried till now is basically place break points in the code to see what happens where and this is the conclusion I've come to.

Any help figuring out the rest of the problem?

Thanks!

Upvotes: 0

Views: 66

Answers (1)

Zach Saucier
Zach Saucier

Reputation: 26014

You can use an if statement to not do prevent the .css commands from being reached. The following should stop it on the third slide

function d(q) {
    var p = g.eq(h);
    console.log('abc');
    if (q === "next") {
        h = h < n - 1 ? ++h : 0
    } else {
        if (q === "prev") {
            h = h > 0 ? --h : n - 1
        }
    }
    var o = g.eq(h);
    if(h !== 3) { 
        p.css("opacity", 0); 
        o.css("opacity", 1); 
    }
}

With this being said, I'd recommend stopping whatever is firing that function in the if statement instead. That way it's not running this function when it's not doing something

Upvotes: 2

Related Questions