index.html 4.18 KB
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
    <link href='https://fonts.googleapis.com/css?family=Signika+Negative:300,400,700' rel='stylesheet' type='text/css'>
    <link href='https://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>
    <div id="banner">
        <div id="emailPath">
            <div id="email"></div>
        </div>
        <div id="man">
            <img src="images/man.png" alt="">
            <div id="arm"></div>
        </div>
    </div>
    <div id="stats">
        <div>duration: <span id="duration">0</span> 1 iteration</div>
        <div>totalDuration: <span id="totalDuration">0</span> all iterations including repeatDelays</div>
        <div>repeat: <span id="repeatCount">0</span> of <span id="totalRepeatCount"></span></div>
        <div>time: <span id="time">1</span></div>
        <div>totalTime: <span id="totalTime">1</span></div>
        <div>progress: <span id="progress">1</span></div>
        <div>totalProgress: <span id="totalProgress">1</span></div>
        <button id="restart">restart()</button>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sizzle/2.2.0/sizzle.js"></script>
    <script>
    var $ = Sizzle,
        $email = $("#email"),
        $arm = $("#arm"),
        tl;
        tlMan;

    var tl = new TimelineMax({
        delay: 1,
        repeat: 0,
        repeatDelay: 1,
        onUpdate: updateStats,
        onRepeat: updateReps,
        onComplete: restart
    });
    var tlMan = new TimelineMax({
        delay: 1,
        repeat: 0,
        repeatDelay: 1,
        onUpdate: updateStats,
        onRepeat: updateReps,
        onComplete: restart
    });
    tlMan.from($arm, 0.5, { 
            rotation: 0 
        }, "+=0.2")
        .to($arm, 0.5, { 
            rotation: 14
        }, "+=0.1");

    //banner animation code (only 11 lines)

    tl.from($email, 0.5, {
            scale: 0,
            autoAlpha: 0
        })
        .to($email, 0.5, {
            scale: 0.5,
            autoAlpha: 1
        })
        .to($email, 0.5, {
            scale: 0.5,
            top: -26
        })
        .to($email, 0.2, {
            scale: 0.5,
            top: -26
        })
        .to($email, 0.6, {
            scale: 1,
            top: 10,
            left: -15
        })
        .to($email, 0.5, {
            scale: 1,
            top: 80,
            left: -22
        }, "+=0.2")
        .to($email, 0.3, {
            left: -24,
            top: 95,
            scale: 0,
            autoAlpha: 0
        }, "+=0.2")
        ;

    var duration = document.getElementById("duration"),
        totalDuration = document.getElementById("totalDuration"),
        repeatCount = document.getElementById("repeatCount"),
        totalRepeatCount = document.getElementById("totalRepeatCount"),
        time = document.getElementById("time"),
        totalTime = document.getElementById("totalTime"),
        progress = document.getElementById("progress"),
        totalProgress = document.getElementById("totalProgress"),
        restart = document.getElementById("restart"),
        reps = 0;

    function updateReps() {
        reps++;
        repeatCount.innerHTML = reps;
    }

    function updateStats() {
        time.innerHTML = tl.time().toFixed(2);
        totalTime.innerHTML = tl.totalTime().toFixed(2);
        progress.innerHTML = tl.progress().toFixed(2);
        totalProgress.innerHTML = tl.totalProgress().toFixed(2);
    }

    function reset() {
        reps = 0;
        duration.innerHTML = tl.duration().toFixed(2);
        totalDuration.innerHTML = tl.totalDuration().toFixed(2);
        repeatCount.innerHTML = reps;
        totalRepeatCount.innerHTML = tl.repeat();
    }

    function restart() {
        TweenLite.to(restart, 0.4, {
            autoAlpha: 1
        })
    }

    restart.onclick = function() {
        reset();
        TweenLite.set(restart, {
            autoAlpha: 0
        })
        tl.restart();
        tlMan.restart();
    }

    reset();
    </script>
</body>

</html>