I'm trying to hover over over the img then use Greensock Tweenmax on hover to control the speed and opacity of the text within the span. The opacity will change on mouseover and mouseout.
The problem is that I'm having to repeat the same exact same effect on several div's and it's becoming repetitive. Each one will be unique to the image being hovered. I don't want them all to appear at the same time when I hover over one div. I could give them all the same class then use .hover
but then that would activate all of them instead of individually.
They are only to appear respective to that particular div being hovered. It works just fine, but I would like to simplify it since I will be doing this to about 20 different div
s.
I need some help simplifying the code below. It works just fine, but maybe there is an easier way.
<a href="#click-for-modal" data-toggle="modal">
<div class="test">
<img src="img/image.png"><span>Here is some text</span>
</div>
</a>
<a href="#click-for-another-modal" data-toggle="modal">
<div class="testx">
<img src="img/image.png"><span>Here is some other text</span>
</div>
</a>
/* tweenmax hover animations */
$('.test img').hover(
function(){
/*mouseover function*/
TweenLite.to(".test span", 1.5, {opacity:1});
},
function(){
/*mouseout function*/
TweenLite.to(".test span", 1.5, {opacity:0});
});
$('.testx img').hover(
function(){
/*mouseover function*/
TweenLite.to(".testx span", 1.5, {opacity:1});
},
function(){
/*mouseout function*/
TweenLite.to(".testx span", 1.5, {opacity:0});
});
$('.testxy img').hover(
function(){
/*mouseover function*/
TweenLite.to(".testxy span", 1.5, {opacity:1});
},
function(){
/*mouseout function*/
TweenLite.to(".testxy span", 1.5, {opacity:0});
});
$('.testxyz img').hover(
function(){
/*mouseover function*/
TweenLite.to(".testxyz span", 1.5, {opacity:1});
},
function(){
/*mouseout function*/
TweenLite.to(".testxyz span", 1.5, {opacity:0});
});