Jump to content
Search Community

sizmek carousel loses click event after first loop

kempo test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I have a banner that has a carousel where each slide has a different clickthrough url. Clickthroughs are added to divs with addEvent. It all seems to work until the carousel loops back to the beginning, when the clickthrough don't work anymore. Here is the js..
 

(function checkInit() {
try {
EB.isInitialized() ? onInit() : EB.addEventListener(EBG.EventName.EB_INITIALIZED, onInit())
} catch (a) {
onInit();
}})();
 
function onInit() {
animate();
} 
 
function animate(){
var delayed = 1.75;
// TweenMax.to(".intro", 1, {y:-250, delay:delayed,ease:Power4.easeIn});
}
 
// Support IE events
function addEvent(evnt, elem, func) {
if (elem.addEventListener){  // W3C DOM
elem.addEventListener(evnt,func,false);
}else if(elem.attachEvent){ // IE DOM
elem.attachEvent("on"+evnt, func);
}else{ // No much to do
     elem[evnt] = func;
  }
}
 
// Events
 
addEvent("click", document.getElementById("next"), function(){
    next();
});
 
addEvent("click", document.getElementById("prev"), function(){
    prev();
});
 
addEvent("click", document.getElementById("r1"), function(){
    EB.clickthrough("url1");
});
 
addEvent("click", document.getElementById("r2"), function(){
    EB.clickthrough("url2");
});
 
addEvent("click", document.getElementById("r3"), function(){
    EB.clickthrough("url3");
});
 
addEvent("click", document.getElementById("r4"), function(){
    EB.clickthrough("url4"); 
});
 
addEvent("click", document.getElementById("r5"), function(){
    EB.clickthrough("url5"); 
});
 
 
var isRunning = false; // Flag to stop carousel spam
var autoRotate = setInterval(next, 5000); // Automatic carousel rotation
 
function prev(){
    clearInterval(autoRotate);
    if(isRunning == false){
        isRunning = true;
        var parentElement = document.getElementById("carousel");
        parentElement.insertBefore(parentElement.childNodes[3],parentElement.childNodes[0]);
        TweenMax.to(".carousel", 0.0, {x:"-=300"});
        TweenMax.to(".item", 0.5, {x:"+=300"});
        setTimeout(function(){
            isRunning = false;
        }, 500);
    }
    autoRotate = setInterval(next, 5000); // Restart the auto-rotate
}
 
function next(){
    clearInterval(autoRotate);
    var parentElement = document.getElementById("carousel");
    if(isRunning == false){
        isRunning = true;
        TweenMax.to(".carousel", 0.5, {x:"-=300"});
        TweenMax.delayedCall(0.5, function(){
            TweenMax.to(".item", 0.0, {x:"+=300"});
            var cln = parentElement.childNodes[0].cloneNode(true);
            parentElement.appendChild(cln);
            parentElement.removeChild(parentElement.childNodes[0]);
            isRunning = false;
        });
    }
    autoRotate = setInterval(next, 5000);
}
Link to comment
Share on other sites

Hi kempo, welcome to the forums!

 

Do you see any errors when the carousel goes back to the beginning? I don't really see any Sizmek-specific code in this JS. Do you have the same error if you run your code without any of the Sizmek API? If it breaks without any of the Sizmek code, then, do you think you could set up a reduced pen example to help us troubleshoot it with you?

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...