Sam Hanson
Sam Hanson

Reputation: 1357

Stop auto play on click round about slider javascript

I have used round about slider from this site.

If i mouseover the slide show the auto rotate stops. I need to stop the auto play on click the link Stop auto play.

My html code:

<div id="carousel">
    <a href="#"><img src="image_main1.jpg" alt=""></a>
    <a href="#" ><img src="image_main2.jpg" alt=""></a>
    <a href="#" ><img src="image_main3.jpg" alt=""></a>
</div>

<div id="carousel-controls">
    <span class="control current"><img src="video_thumb1.jpg" alt=""></span>
    <span class="control"><img src="video_thumb.jpg2" alt=""></span>
    <span class="control"><img src="video_thumb.jpg3" alt=""></span>
</div>
<div><a href="#">Stop auto play</a></div>

My script:

(function($) {

var $descriptions = $('#carousel-descriptions').children('li'),
    $controls = $('#carousel-controls').find('span'),
    $carousel = $('#carousel')
        .roundabout({childSelector:"a", minOpacity:1, autoplay:true, autoplayDuration:5000, autoplayPauseOnHover:true })
        .on('focus', 'a', function() {
            var slideNum = $carousel.roundabout("getChildInFocus");

            $descriptions.add($controls).removeClass('current');
            $($descriptions.get(slideNum)).addClass('current');
            $($controls.get(slideNum)).addClass('current');

        });


$controls.on('click dblclick', function() {
    var slideNum = -1,
        i = 0, len = $controls.length;

    for (; i<len; i++) {
        if (this === $controls.get(i)) {
            slideNum = i;
            break;
        }
    }

    if (slideNum >= 0) {
        $controls.removeClass('current');
        $(this).addClass('current');
        $carousel.roundabout('animateToChild', slideNum);
    }
});

}(jQuery));

How to do that?

Upvotes: 0

Views: 6854

Answers (2)

slowe
slowe

Reputation: 336

From the API page (http://fredhq.com/projects/roundabout#/api), btnStopAutoplay is "A jQuery selector of page elements that, when clicked, will stop the Roundabout’s autoplay feature (if it’s current playing). "

So, first add an ID so it can be selected

<div><a href="#" id="carouselstop">Stop auto play</a></div>

Then, update your Javascript to include the btnStopAutoplay:

.roundabout({childSelector:"a", minOpacity:1, autoplay:true, autoplayDuration:5000, autoplayPauseOnHover:true, btnStopAutoplay:"#carouselstop" })

Upvotes: 1

Dineshkani
Dineshkani

Reputation: 3005

You can stop the autoplay by set the boolean value as false

<div><a href="#" onclick='$('#carousel').roundabout({autoplay: false});'>Stop auto play</a></div>

See this link for reference

Upvotes: 0

Related Questions