Link to home
Start Free TrialLog in
Avatar of djfenom
djfenom

asked on

Javascript Carousel not working properly

I'm putting together a page which when a thumbnail is clicked a larger version of the image fades in along with some text to go with it. I've got it working here, http://www.emtrade.arrivalpreview.co.uk/shot-blasting/shot-blasting-portfolio.html.

My problem is, only the first 2 work properly, once you click a different one, the first 2 appear to repeat again, which is really weird!

The main javascript file is home.js, which is as follows.

Many thanks

Chris
function clearOn(){
	var links = document.getElementsByTagName('A');
	for(var i=0; i < links.length; i++){
		if(links[i].className == "onstate"){
			links[i].className = "";
		}
	}
}
window.addEvent("domready", function() {   
    var Carousel = new iCarousel("carousel_content", {
        idPrevious: "carousel_previous",
        idNext: "carousel_next",
        idToggle: "undefined",
        item: {   
            klass: "carousel_item",
            size: 494   
        },   
        animation: {   
			type: 'fade'  
        }
    });   
  
    $("thumb0").addEvent("click", function(event){new Event(event).stop();Carousel.goTo(0);clearOn();this.className = 'onstate';});
    $("thumb1").addEvent("click", function(event){new Event(event).stop();Carousel.goTo(1);clearOn();this.className = 'onstate';});   
    $("thumb2").addEvent("click", function(event){new Event(event).stop();Carousel.goTo(2);clearOn();this.className = 'onstate';});   
    $("thumb3").addEvent("click", function(event){new Event(event).stop();Carousel.goTo(3);clearOn();this.className = 'onstate';});   
    $("thumb4").addEvent("click", function(event){new Event(event).stop();Carousel.goTo(4);clearOn();this.className = 'onstate';});   
    $("thumb5").addEvent("click", function(event){new Event(event).stop();Carousel.goTo(5);clearOn();this.className = 'onstate';}); 
}); 
 
window.addEvent("domready", function() {   
    var Carousel1 = new iCarousel("text_slider_gal", {
		idPrevious: "carousel_previous",
		idNext: "carousel_next",
		idToggle: "undefined",
		item: {
			klass: "text_slider_item",
			size: 194
		},
		animation: {
			type: 'fade'
		}
	}); 
  
    $("thumb0").addEvent("click", function(event){new Event(event).stop();Carousel1.goTo(0);clearOn();this.className = 'onstate';});
    $("thumb1").addEvent("click", function(event){new Event(event).stop();Carousel1.goTo(1);clearOn();this.className = 'onstate';});
    $("thumb2").addEvent("click", function(event){new Event(event).stop();Carousel1.goTo(2);clearOn();this.className = 'onstate';});
    $("thumb3").addEvent("click", function(event){new Event(event).stop();Carousel1.goTo(3);clearOn();this.className = 'onstate';});
    $("thumb4").addEvent("click", function(event){new Event(event).stop();Carousel1.goTo(4);clearOn();this.className = 'onstate';});
    $("thumb5").addEvent("click", function(event){new Event(event).stop();Carousel1.goTo(5);clearOn();this.className = 'onstate';});
});

Open in new window

Avatar of djfenom
djfenom

ASKER

Anybody?
Avatar of b0lsc0tt
I can tell you the scripts are not changing the right element to visible for some reason.  Because of how both Mootools and iCarousel obfuscate the code and the lack of explanation of especially the iCarousel code I can't easily tell you why.  For some reason it is just showing/hiding the first two items.  If you use a tool to look at the html source made by the page you can see onstate is set in the class of each thumb just as it should but the css for the description and big picture is not changed in the right element.

I have spent a few minutes trying to find a problem in your JS files or html.  I can't and with the other info I have found and testing I have done it seems like it is related or caused by either the iCarousel or Mootools JS files.  I can't tell you how to fix those though.

Do you have another page using iCarousel and more than 2 images?  Does it work?  If you don't have one try to make a basic page to see if you can get it to work with more than 2.  It would help to "prove" where the problem is.

Let me know how this helps or if you have a question.

bol
Avatar of djfenom

ASKER

Thanks bol, I have used iCarousel before here, www.arrivaldesign.co.uk and didn't have a problem, although that was using a scrolling action rather than a fading one?
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America 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
Avatar of djfenom

ASKER

Thanks bol, I've managed to get it working now, had to use 14 blank <li class="carousel_item"></li> and 14 blank <div class="text_slider_item"></div> !!

Not ideal, but it's working for the time being!

Very odd!
Your welcome!  I'm glad I could help.  Thanks for the fun question, the grade and the points.

bol