Update To Sample
by rhernando
HTML
<script src="http://www.websnap.cl/samples/scripts/TweenMax.min.js"></script>
<p><button id="btn1">Tween</button> <button id="btn2">Reverse Tween</button></p>
<p><span style="float:left;">The blue div current position is: </span><div style="float:left; border:solid 1px #000; height:25px; width:150px; margin:5px;" id="log"></div>
<div style="clear:both;"></div>
<div style="border:solid 1px #000; height:25px; width:250px; margin:5px;" id="log1"></div>
<div class="div1" id="div1"><b>CLICK ME TO MAKE ME BIGGER!!!</b></div>
CSS
html, body{
margin:0;
font-family:Verdana, Geneva, sans-serif;
font-size:14px;
}
.div1{
width:400px;
height:200px;
background-color:#00F;
position:relative;
}
.div2{
width:400px;
height:200px;
background-color:#F00;
position:relative;
}
JavaScript
var elem1 = $("div#div1"),
width1 = elem1.width();
var tn1 = new TweenMax.to($("div#div1"), 1, {css:{left:'-' + width1 + 'px'}, paused:true, onUpdate:tn1Update, onReverseComplete:tn1RevComplete});
$("button#btn1").click(function()
{
$("div#log1").empty();
tn1.play();
});
$("button#btn2").click(function()
{
tn1.reverse();
});
elem1.click(function()
{
var newWidth1 = width1 * 1.5;
$(this).width(newWidth1);
tn1.updateTo({css:{left:'-' + newWidth1 + 'px'}}, false);
});
function tn1Update()
{
$("div#log").html(elem1.position().left);
}
function tn1RevComplete()
{
tn1.invalidate();
tn1.updateTo({css:{left:'-' + width1 + 'px'}}, false);
elem1.width(width1);
$("div#log1").html("<span>TWEEN REVERSE COMPLETED!!!</span>");
}