I am trying to enliven the exchange of images when hovering over different elements on the page. I am using GSAP for now, but will be open to a simpler solution using jQuery or just CSS, if possible.
I already know that I'm wrong, given how much code I wrote for this. There should be a simpler solution (and it doesn't even work, it is).
Here is what I have so far so that you understand what I'm trying to accomplish:
http://codepen.io/jakatz/pen/GorLZb
This is the javascript / gsap code:
$(document).ready(function() {
var image1 = document.querySelector('#image1');
var image2 = document.querySelector('#image2');
var image3 = document.querySelector('#image3');
var activeImage = document.querySelector('.image-container .active');
$('.item1').hover(function() {
TweenMax.to(image1, 0.5, {
left: 0
});
TweenMax.to(activeImage, 0.5, {
left: 1500,
onComplete: function() {
$('.image').removeClass('active');
$('#image1').addClass('active');
activeImage = document.querySelector('.image-container .active');
}
});
});
$('.item2').hover(function() {
TweenMax.to(image2, 0.5, {
left: 0
});
TweenMax.to(activeImage, 0.5, {
left: 1500,
onComplete: function() {
$('.image').removeClass('active');
$('#image2').addClass('active');
activeImage = document.querySelector('.image-container .active');
}
});
});
$('.item3').hover(function() {
TweenMax.to(image3, 0.5, {
left: 0
});
TweenMax.to(activeImage, 0.5, {
left: 1500,
onComplete: function() {
$('.image').removeClass('active');
$('#image3').addClass('active');
activeImage = document.querySelector('.image-container .active');
}
});
});
});
This works for the most part, until you move a new element before the end of the previous animation ... this will break it. Any help would be greatly appreciated!