Share Posted May 21, 2015 Hi, I'm really new to all this and this is my second post. I'm trying to do something I thought was simple, but something does not work. I have two div (#red and #blue) and two buttons (#opacity1 and #opacity2), clicking the first button will increase the opacity of the first div while decreasing the opacity of the second div and vice versa. The code I'm using doesn't seems to work, can someone help? Thanks UPDATE: There's an error in the code, sorry!!! .to("#blue", 0.1, { opcity: "+=0.1" }, "0"); should be .to("#blue", 0.1, { opacity: "+=0.1" }, "0"); (opacity instead of opcity) and now seems to works. Anyway, am I doing this correctly? or there is a better way? Thanks. $('#opacity1').click(function() { var tl1 = new TimelineMax(); tl1.to("#red", 0.1, {opacity: "-=0.1" }, "0") .to("#blue", 0.1, { opacity: "+=0.1" }, "0"); }); $('#opacity2').click(function() { var tl2 = new TimelineMax(); tl2.to("#red", 0.1, {opacity: "+=0.1" }, "0") .to("#blue", 0.1, { opacity: "-=0.1" }, "0"); }); See the Pen VLKjzL?editors=011 by uomopalese (@uomopalese) on CodePen Link to post Share on other sites
Share Posted May 21, 2015 Hi uomopalese try this : var Op = 5 ; $('#opacity1').click(function() { if(Op<10){ Op +=1; TweenLite.to("#red", 0.1, {opacity: "+=0.1" }); TweenLite.to("#blue", 0.1, { opacity: "-=0.1" }); } }); $('#opacity2').click(function() { if(Op>0){ Op -=1; TweenLite.to("#red", 0.1, {opacity: "-=0.1" }); TweenLite.to("#blue", 0.1, { opacity: "+=0.1" }); } }); 1 Link to post Share on other sites
Author Share Posted May 21, 2015 Hi Diaco.AW thanks for your answer, this forum is unbelievable! I tried your code and it works fine, but if I increase the duration of the tween, eg: TweenLite.to("#red", 0.5, {opacity: "+=0.1" }); the behaviour changes, the divs doesn't desapear completely (if i click quickly). Is there a reason for this? I wouuld like to add some easing effects on the clicks (i updated the codepen with your code). Thanks a lot! Link to post Share on other sites
Solution Share Posted May 21, 2015 you need isActive try something like this : See the Pen GJjmYK by MAW (@MAW) on CodePen 1 Link to post Share on other sites
Author Share Posted May 22, 2015 HI, thanks again, it works even if it's more complicated than i thought, i guess i need to improve my knowledge both on JS and TweenMax. Thanks a lot for your time, i really appreciate your kindness. gio 1 Link to post Share on other sites