Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Andreas Anastasiades
2,916 Pointsloop slideshow
I'm trying to loop a slideshow but can't seem to figure it out.
This is what I've got so far
autoPlay: function() {
clearTimeout(this.timer);
//auto play
if( HomePageSlider.currentPosition < HomePageSlider.numberOfSlides ){
this.timer = setTimeout(function () {
HomePageSlider.right();
HomePageSlider.currentPosition++;
}, 4500);
}
}
So it sets the position to 0 and counts how many images I have. Slider keeps moving right to the next image until it's on the last slide. Then it stops, which is okay for now. But now I want it to restart from first image.
Anyone got a clue? Thanks!
Per Karlsson
12,683 PointsNot entirely sure if this works but you could try to add an else clause.
if( HomePageSlider.currentPosition < HomePageSlider.numberOfSlides ){
this.timer = setTimeout(function () {
HomePageSlider.right();
HomePageSlider.currentPosition++;
}, 4500);
} else {
HomePageSlider.currentPosition = 0;
}
1 Answer
Andreas Anastasiades
2,916 PointsHi Per,
I've tried this as well without result..
If it helps, I have an example on this link http://typograficsonline.be/VTK/ it's the images you see on the homepage. They play automatically but stop at the last slide.
Andreas Anastasiades
2,916 PointsAndreas Anastasiades
2,916 PointsI'm still building on this: https://teamtreehouse.com/community/autoplay-slider-in-wp-theme