Link to home
Start Free TrialLog in
Avatar of Courtney Whiting
Courtney WhitingFlag for United States of America

asked on

Javascript Carousel

I am trying to create a auto-rotating carousel that performs several events with each change. I thought that I might be on the right track with where I am now but it isn't working. Any ideas? Thanks!
function changeSlide1() {
	document.querySelector('#carousel-img').src = "images/slide1.jpg";
	document.querySelector('#description').style.visibility = "visible";
	document.querySelector('#img-1').style.opacity = "1";
	document.querySelector('#img-2').style.opacity = "0.3";
	document.querySelector('#img-3').style.opacity = "0.3";
}

function changeSlide2() {
	document.querySelector('#carousel-img').src = "images/slide-2.jpg";
	document.querySelector('#description').style.visibility = "hidden";
	document.querySelector('#img-2').style.opacity = "1";
	document.querySelector('#img-1').style.opacity = "0.3";
	document.querySelector('#img-3').style.opacity = "0.3";
}

function changeSlide3() {
	document.querySelector('#carousel-img').src = "images/slide-3.jpg";
	document.querySelector('#description').style.visibility = "hidden";
	document.querySelector('#img-3').style.opacity = "1";
	document.querySelector('#img-1').style.opacity = "0.3";
	document.querySelector('#img-2').style.opacity = "0.3";
}

var changeArray = [
	changeSlide1,
	changeSlide2,
	changeSlide3
];

var count = 1;
window.setInterval(function() {
	changeArray[count];
	count++
	if (count > 2) {
		count = 0;	
	}
}, 4000)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Courtney Whiting

ASKER

This code was great. As I implemented it though I realized that I would require a lot of follow up functionality (making the carousel stop when somethings clicked on, etc) and so I decided to keep it simple and not have the carousel auto rotate.

Thank you so much though Julian for helping out with that late night project!! You really came through when I just couldn't find the information I was looking for elsewhere.
You are most welcome Courtney.