Checking total duration of the animation with TweenMax.js
An example of checking total duration of the animation with TweenMax.js.
<!DOCTYPE html>
<html>
<head>
<script src="js/plugins/BezierPlugin.min.js"></script>
<script src="js/easing/EasePack.min.js"></script>
<script src="js/TweenMax.min.js"></script>
</head>
<body>
<button id="seekBut" onclick="seekAnimation()">Check total duration of the animation</button>
<br>
<canvas id="myCanvas" width="700" height="300"></canvas>
<div id="textDiv"></div>
<script>
var txtdiv = document.getElementById('textDiv');
var context, canvas, myRectangle, tween;
canvas = document.getElementById('myCanvas');
context = canvas.getContext('2d');
function drawRectangle(myRectangle, context) {
context.beginPath();
context.rect(myRectangle.x, myRectangle.y, myRectangle.width, myRectangle.height);
context.fillStyle = '#00ff00';
context.fill();
context.lineWidth = myRectangle.borderWidth;
context.strokeStyle = 'black';
context.stroke();
}
function renderCanvas() {
context.clearRect(0, 0, canvas.width, canvas.height);
drawRectangle(myRectangle, context);
}
myRectangle = {
x: 10,
y: 100,
width: 50,
height: 50,
borderWidth: 5
};
function seekAnimation() {
var td = tween.totalDuration()
txtdiv.innerHTML = "total duration = " + td;
}
// creating a tween as a variable
tween = new TweenMax(myRectangle, 5, {x:"+=300", y:"+=100", width:50, height:50, borderWidth: 5, onUpdate:renderCanvas });
tween.play(); // playing the tween
</script>
</body>
</html>