Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Pause for Custom Carousel

Avatar

Avatar
Validate 10
Level 2
sunitac70336244
Level 2

Likes

7 likes

Total Posts

65 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 10
Level 2
sunitac70336244
Level 2

Likes

7 likes

Total Posts

65 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile
sunitac70336244
Level 2

05-02-2019

Dear All,

We need a pause button in our custom carousel , which is migrated from AEM 5.6 to AEM 6.4.

The new requirement is , if somebody will click on pause button then the carousel slide will pause and  again they will click on same pause button then the the slide will again play with time interval 3 seconds...

In the below code , i have written the pause functionality...But It is not working , as expected.

<sly data-sly-use.carousel = "com.trp.wtc.sunita.pojo.LandingPosterCarouselTest"/>

<div>Landing Page Carousel Testing Here</div>

<div id="myCarousel" class="carousel-eb carousel slide" data-ride="carousel" data-interval="3000">

<sly data-sly-test="${carousel.slidesList}">

<div class="carousel-inner ${properties.addPadding ? 'carousel-inner-eb' : ''}" role="listbox">

<sly data-sly-list="${carousel.slidesList}">

<div class="item ${item.count == '0' ? 'active' : ''}">

<sly data-sly-test="${item.bgImage}">

<img src="${item.bgImage}" style="width:100%" alt="">

<div class="overlay"></div>

</sly>

</div>

</sly>

</div>

</sly>

<sly data-sly-test.slide="${carousel.slidesList}">

<sly data-sly-test="${slide.size > 1}">

<a id="left" class="left carousel-control ${properties.addPadding?'':'carousel-control-np'} left-arrow ${item.count}" href="#myCarousel" data-slide="prev" >

<em class="fa fa-angle-left"></em>

</a>

<a id="right" class="right carousel-control ${properties.addPadding? '' :'carousel-control-np'} right-arrow" href="#myCarousel" data-slide="next" >

<em class="fa fa-angle-right"></em>

</a>

<div class="${properties.addPadding? '' : 'indicator-eb' }">

<ol class="carousel-indicators">

<sly data-sly-list="${carousel.slidesList}">

<li data-target="#myCarousel" data-slide-to="${item.count}" class="${item.count == '0' ? 'active' : ''}"></li>

</sly>

<button class="controls" id="pause">Pause</button>

</ol>

</div>

</sly>

</sly>

</div>

<script>

   var slides = document.querySelectorAll('#slides .myCarousel');

var currentSlide = 0;

var slideInterval = setInterval(nextSlide,3000);

function nextSlide(){

slides[currentSlide].className = 'myCarousel';

currentSlide = (currentSlide+1)%slides.length;

slides[currentSlide].className = 'item1 active';

}

var playing = true;

var pauseButton = document.getElementById('pause');

function pauseSlideshow(){

pauseButton.innerHTML = 'Play';

playing = false;

clearInterval(slideInterval);

}

function playSlideshow(){

pauseButton.innerHTML = 'Pause';

playing = true;

slideInterval = setInterval(nextSlide,3000);

}

pauseButton.onclick = function(){

if(playing){ pauseSlideshow(); }

else{ playSlideshow(); }

};

</script>

My website page is coming like below.

1684891_pastedImage_6.png

But when I click on Pause button then it is not working as expected. Can you please help me on this.

View Entire Topic

Avatar

Avatar
Give back 300
MVP
Gaurav-Behl
MVP

Likes

243 likes

Total Posts

1,145 posts

Correct Reply

281 solutions
Top badges earned
Give back 300
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Give back 300
MVP
Gaurav-Behl
MVP

Likes

243 likes

Total Posts

1,145 posts

Correct Reply

281 solutions
Top badges earned
Give back 300
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
Gaurav-Behl
MVP

05-02-2019

try this -

var currentSlide = 0;

var playing = true;

var slideInterval = setInterval(nextSlide,3000);

function nextSlide(){

     var slidesC = document.querySelectorAll('#myCarousel .carousel-inner .item');

if(undefined != slidesC[currentSlide]) {

slidesC[currentSlide].className = 'item';

currentSlide = (currentSlide+1)%slidesC.length;

slidesC[currentSlide].className = 'item active';

}

}

function pauseSlideshow(){

document.getElementById('pauseButton').innerHTML = 'Play';

playing = false;

clearInterval(slideInterval);

}

function playSlideshow(){

document.getElementById('pauseButton').innerHTML = 'Pause';

playing = true;

slideInterval = setInterval(nextSlide,2000);

}

   function myFunction(){

            if(playing){ pauseSlideshow(); }

            else{ playSlideshow(); }

};