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

JavaScript

Altering my slider code to slide instead of cycle

I am trying to make a slider so far my code is working it is just cycling the images, now I am wondering if there is a way to alter it, so it will slide the images instead of cycling them. I don't want to use jquery though.

<script> var picCounter = 1; var total = 6; function slide (value) {

var image = document.getElementById('img');

picCounter = picCounter + value;

if (picCounter > total) {
    picCounter = 1;
} else if (picCounter < 1) {
    picCounter = total;
} else {
    image.src = "images/angel"+ picCounter+".jpg";
}}

function autoSlide(){

var image = document.getElementById('img');

picCounter ++;

if (picCounter > total) {
    picCounter = 1;
} else if (picCounter < 1) {
    picCounter = total;
} else {
    image.src = "images/angel"+ picCounter+".jpg";
}}

var stopandplay = setInterval(autoSlide,3000);

//slider stop and play functions

function stopit(){ clearInterval(stopandplay); } function playit() { stopandplay = setInterval(autoSlide,3000); } </script>

1 Answer

jared eiseman
jared eiseman
29,023 Points

Without JQuery, you'll probably need to do some sort of fanciness with creating CSS transitions.