I have the following javascript that i’m trying to run on my site, but it doesn’t work. My question is how can i write this so that it runs? The javascript in question is structured the following way:
var callout1_location = 1,
callout2_location = 0,
callout3_location = 3;
$( ".js-infographic__callout1" ).click(function() {
var tl = new TimelineMax();
if (callout1_location == 1) {
tl.to(".js-infographic__callout-wrapper", 1, {rotation:120}, 0)
.to(".js-infographic__callout1", 1, {rotation:-120, backgroundColor:"#D0D465"}, 0)
.to(".js-infographic__callout1 path", 1, {fill:"white"}, 0)
.to(".js-infographic__callout2", 1, {rotation:-120, backgroundColor:"white"}, 0)
.to(".js-infographic__callout2 path", 1, {fill:"#D0D465"}, 0)
.to(".js-infographic__callout3", 1, {rotation:-120, backgroundColor:"white"}, 0)
.to(".js-infographic__callout3 path", 1, {fill:"#D0D465"}, 0)
.call(function(){ callout1_location = 2 }, 0)
.call(function(){ callout2_location = 3 }, 0)
.call(function(){ callout3_location = 1 }, 0)
.to(".js-infographic__description1", 1, {y:50, opacity:1}, 0)
.to(".js-infographic__description2", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description3", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description2", 0, {y:0}, 1)
.to(".js-infographic__description3", 0, {y:0}, 1);
}
if (callout1_location == 3) {
tl.to(".js-infographic__callout-wrapper", 1, {rotation:120}, 0)
.to(".js-infographic__callout1", 1, {rotation:-120, backgroundColor:"#D0D465"}, 0)
.to(".js-infographic__callout1 path", 1, {fill:"white"}, 0)
.to(".js-infographic__callout2", 1, {rotation:-120, backgroundColor:"white"}, 0)
.to(".js-infographic__callout2 path", 1, {fill:"#D0D465"}, 0)
.to(".js-infographic__callout3", 1, {rotation:-120, backgroundColor:"white"}, 0)
.to(".js-infographic__callout3 path", 1, {fill:"#D0D465"}, 0)
.call(function(){ callout1_location = 2 }, 0)
.call(function(){ callout2_location = 1 }, 0)
.call(function(){ callout3_location = 3 }, 0)
.to(".js-infographic__description1", 1, {y:50, opacity:1}, 0)
.to(".js-infographic__description2", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description3", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description2", 0, {y:0}, 1)
.to(".js-infographic__description3", 0, {y:0}, 1);
}
});
$( ".js-infographic__callout2" ).click(function() {
var tl = new TimelineMax();
if (callout2_location == 0) {
tl.to(".js-infographic__callout2", 1, {backgroundColor:"#D0D465"}, 0)
.to(".js-infographic__callout2 path", 1, {fill:"white"}, 0)
.call(function(){ callout1_location = 1 }, 0)
.call(function(){ callout2_location = 2 }, 0)
.call(function(){ callout3_location = 3 }, 0)
.to(".js-infographic__description1", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description2", 1, {y:50, opacity:1}, 0)
.to(".js-infographic__description3", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description1", 0, {y:0}, 1)
.to(".js-infographic__description3", 0, {y:0}, 1);
}
if (callout2_location == 1) {
tl.to(".js-infographic__callout-wrapper", 1, {rotation:0}, 0)
.to(".js-infographic__callout1", 1, {rotation:0, backgroundColor:"white"}, 0)
.to(".js-infographic__callout1 path", 1, {fill:"#D0D465"}, 0)
.to(".js-infographic__callout2", 1, {rotation:0, backgroundColor:"#D0D465"}, 0)
.to(".js-infographic__callout2 path", 1, {fill:"white"}, 0)
.to(".js-infographic__callout3", 1, {rotation:0, backgroundColor:"white"}, 0)
.to(".js-infographic__callout3 path", 1, {fill:"#D0D465"}, 0)
.call(function(){ callout1_location = 1 }, 0)
.call(function(){ callout2_location = 2 }, 0)
.call(function(){ callout3_location = 3 }, 0)
.to(".js-infographic__description1", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description2", 1, {y:50, opacity:1}, 0)
.to(".js-infographic__description3", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description1", 0, {y:0}, 1)
.to(".js-infographic__description3", 0, {y:0}, 1);
}
if (callout2_location == 3) {
tl.to(".js-infographic__callout-wrapper", 1, {rotation:0}, 0)
.to(".js-infographic__callout1", 1, {rotation:0, backgroundColor:"white"}, 0)
.to(".js-infographic__callout1 path", 1, {fill:"#D0D465"}, 0)
.to(".js-infographic__callout2", 1, {rotation:0, backgroundColor:"#D0D465"}, 0)
.to(".js-infographic__callout2 path", 1, {fill:"white"}, 0)
.to(".js-infographic__callout3", 1, {rotation:0, backgroundColor:"white"}, 0)
.to(".js-infographic__callout3 path", 1, {fill:"#D0D465"}, 0)
.call(function(){ callout1_location = 1 }, 0)
.call(function(){ callout2_location = 2 }, 0)
.call(function(){ callout3_location = 3 }, 0)
.to(".js-infographic__description1", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description2", 1, {y:50, opacity:1}, 0)
.to(".js-infographic__description3", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description1", 0, {y:0}, 1)
.to(".js-infographic__description3", 0, {y:0}, 1);
}
});
$( ".js-infographic__callout3" ).click(function() {
var tl = new TimelineMax();
if (callout3_location == 1) {
tl.to(".js-infographic__callout-wrapper", 1, {rotation:-120}, 0)
.to(".js-infographic__callout1", 1, {rotation:120, backgroundColor:"white"}, 0)
.to(".js-infographic__callout1 path", 1, {fill:"#D0D465"}, 0)
.to(".js-infographic__callout2", 1, {rotation:120, backgroundColor:"white"}, 0)
.to(".js-infographic__callout2 path", 1, {fill:"#D0D465"}, 0)
.to(".js-infographic__callout3", 1, {rotation:120, backgroundColor:"#D0D465"}, 0)
.to(".js-infographic__callout3 path", 1, {fill:"white"}, 0)
.call(function(){ callout1_location = 3 }, 0)
.call(function(){ callout2_location = 1 }, 0)
.call(function(){ callout3_location = 2 }, 0)
.to(".js-infographic__description1", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description2", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description3", 1, {y:50, opacity:1}, 0)
.to(".js-infographic__description2", 0, {y:0}, 1)
.to(".js-infographic__description1", 0, {y:0}, 1);
}
if (callout3_location == 3) {
tl.to(".js-infographic__callout-wrapper", 1, {rotation:-120}, 0)
.to(".js-infographic__callout1", 1, {rotation:120, backgroundColor:"white"}, 0)
.to(".js-infographic__callout1 path", 1, {fill:"#D0D465"}, 0)
.to(".js-infographic__callout2", 1, {rotation:120, backgroundColor:"white"}, 0)
.to(".js-infographic__callout2 path", 1, {fill:"#D0D465"}, 0)
.to(".js-infographic__callout3", 1, {rotation:120, backgroundColor:"#D0D465"}, 0)
.to(".js-infographic__callout3 path", 1, {fill:"white"}, 0)
.call(function(){ callout1_location = 3 }, 0)
.call(function(){ callout2_location = 1 }, 0)
.call(function(){ callout3_location = 2 }, 0)
.to(".js-infographic__description1", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description2", 0.5, {y:100, opacity:0}, 0)
.to(".js-infographic__description3", 1, {y:50, opacity:1}, 0)
.to(".js-infographic__description2", 0, {y:0}, 1)
.to(".js-infographic__description1", 0, {y:0}, 1);
}
});
