[AngularJS+ GSAP] Greensock TimelineLite Animation Sequences

TimelineLite is a piece of the Greensock TweenMax library that provides the ability to create sequenced animation with very little code or setup.

Key value:

fromTo( target:Object, duration:Number, fromVars:Object, toVars:Object, position:* ) 

Read More: https://egghead.io/lessons/angularjs-greensock-timelinelite-animation-sequences

Example:

angular.module(‘website‘, [‘ngAnimate‘])
    .controller(‘MainCtrl‘, function ($scope) {
        $scope.slides = [
            {bg: ‘images/bg3.jpg‘, avatar: ‘images/john.png‘, title: ‘Big Boss‘, subtitle: ‘Monkey king‘},
            {bg: ‘images/bg1.jpg‘, avatar: ‘images/joel.png‘, title: ‘Second Boss‘, subtitle: ‘Monkey leader‘},
            {bg: ‘images/bg2.jpg‘, avatar: ‘images/lukas.png‘, title: ‘Other monkeys‘, subtitle: ‘MOPSI‘}
        ];

        $scope.direction = ‘left‘;
        $scope.currentIndex = 0;

        $scope.setCurrentSlideIndex = function (index) {
            $scope.direction = (index > $scope.currentIndex) ? ‘left‘ : ‘right‘;
            $scope.currentIndex = index;
        };

        $scope.isCurrentSlideIndex = function (index) {
            return $scope.currentIndex === index;
        };
    })
    .animation(‘.slide-animation‘, function () {
        return {
            //remove the current card
            beforeAddClass: function (element, className, done) {

                if (className == ‘ng-hide‘) {
                    var scope = element.scope(),
                        finishPoint = element.parent().width();
                    console.log(element.parent().width());

                    if(scope.direction !== ‘right‘) finishPoint = -finishPoint;

                    TweenLite.to(element, 0.5, {left:finishPoint, ease: Ease.easeInOut, onComplete: done});
                }
                else {
                    done();
                }
            },
            //fade in selected card
            removeClass: function (element, className, done) {
                if (className == ‘ng-hide‘) {
                    var scope = element.scope(),
                        startPoint = element.parent().width(),
                        //start a timeline
                        tl = new TimelineLite();

                    if(scope.direction === ‘right‘) startPoint = -startPoint;

                    //chain methods, animate one by one
                    //.fromTo( target:Object, duration:Number, fromVars:Object, toVars:Object, position:* )
                    //fromTo(element.find(‘.title‘), 0.5, { left: -200, alpha: 0}, {left:0, alpha:1, ease:Ease.easeInOut} )
                    //element.find(‘.title‘): find the element
                    //0.5: 500ms
                    //{left: -200, alpha: 0}: animate start with left: -200 and alpha : 0
                    //{left: 0, alpha: 1, ease: Ease.easeInOut}: animate end with left: 0....
                    tl.fromTo(element, 0.1, { left: startPoint}, {left:0, ease: Ease.easeInOut, onComplete: done})
                        .fromTo(element.find(‘.title‘), 0.5, { left: -200, alpha: 0}, {left:0, alpha:1, ease:Ease.easeInOut} )
                        .fromTo(element.find(‘.subtitle‘), 0.5, { left: -200, alpha: 0}, {left:0, alpha:1, ease:Ease.easeInOut} )
                        .fromTo(element.find(‘.avatar‘), 0.5, { left: 800, alpha: 0}, {left:380, alpha:1, ease:Ease.easeInOut} );
                }
                else {
                    done();
                }
            }
        };
    }); 
<!DOCTYPE html>
<html ng-app="website">
    <head>
        <meta charset="utf-8">
        <title>Egghead.io - Greensock TimelineLite</title>

        <link href="assets/css/bootstrap.css" rel="stylesheet">
        <link rel="stylesheet" href="assets/css/timeline.greensock.css">
    </head>

    <body ng-controller="MainCtrl">

        <div class="slider">
            <div ng-repeat="slide in slides"
                 ng-hide="!isCurrentSlideIndex($index)"
                 class="slide slide-animation">
                <img class="nonDraggableImage" ng-src="{{slide.bg}}">
                <img class="nonDraggableImage avatar" ng-src="{{slide.avatar}}">
                <h1 class="title"><span>{{slide.title}}</span></h1>
                <h3 class="subtitle"><span>{{slide.subtitle}}</span></h3>
            </div>
        </div>

        <div class="nav">
            <div ng-repeat="slide in slides"
                 ng-class="{‘active‘:isCurrentSlideIndex($index)}"
                 ng-click="setCurrentSlideIndex($index)">
                <h3>{{slide.title}}</h3>
            </div>
        </div>

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-animate.min.js"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/gsap/1.10.3/TweenMax.min.js"></script>

        <script src="js/timeline.greensock.js"></script>

    </body>
</html>
时间: 2025-01-16 14:21:24

[AngularJS+ GSAP] Greensock TimelineLite Animation Sequences的相关文章

GASP动画的基本使用

GSAP(TimelineMax.TweenMax) 什么是GSAP? GSAP(GreenSock Animation Platform)是一个从flash时代一直发展到今天的专业动画库. GSAP优点 1.速度快.GSAP专门优化了动画性能,使之实现和CSS一样的高性能动画效果.2.轻量与模块化.模块化与插件式的结构保持了核心引擎的轻量,TweenLite包非常小(基本上低于7kb).GSAP提供了TweenLite, TimelineLite, TimelineMax 和 TweenMax

Dojo特效(翻译)

http://dojotoolkit.org/documentation/tutorials/1.10/effects/index.html In this tutorial, we will explore the effects that Dojo provides, which allow us to jazz up your page or application! 在本教程中,我们会探索dojo提供的特效功能,这可以使我们的Web页面或应用更加生动活泼. Getting Started

CETM51 – Computer Architectures &amp; Networks

Faculty of Technology – School of Computer ScienceCETM51 – Computer Architectures & NetworksAssignment 1 of 2The following outcomes will be assessed:Knowledge Critical understanding of the key system components of a modern computer system. Critical u

javascript animation lib greensock gsap介绍

一般前台做动画有以下几种方式: 1. 简单的css transition动画; 2. css animation动画 3. javascript库动画 一般来说css html5动画只适用于简单的形变动画,动画操作的是css某个属性. 但是对于更加复杂的动画,我们可能必须通过javascript来做,其中greensock的gsap就是一个让你发挥无限想象的强大工具 gsap还支持模块化使用,这一点对于es6爱好者模块化编程的工程师来说是一个福音,支持下面的应用模式 npm install gs

TweenMax的GSAP(GreenSock动画平台)GSAP,专业的Web动画库

很好奇红框框里面的内容是什么,于是点了进去,又百度了下这个英文缩写具体指的什么东西. GSAP的全名是GreenSock Animation Platform,是一个从flash时代一直发展到今天的专业动画库. (据说当初是做flash的,但是flash在逐渐地淡出舞台时,所以开始添加了一些类,加上一些js的动画) 源码里面又有一系列文件  那么他们关系是什么呢?以下图片来源网络 TweenLite.js.TweenMax.js.TimelineLite.js和TimelineMax.js4个文

AngularJS Animation是如何运作的?

当Angular往repeat list里面加入一个元素的时候,.ng-enter 和 .ng-enter CSS 类会被自动赋予给该元素.以下是enter:新增.leave:移除.move:移动位置 这三种不同的情况下,该元素的类变化情况: 事件 初始类 终结类 触发该CSS类变化的指令 enter .ng-enter .ng-enter-active ngRepeat, ngInclude, ngIf, ngView leave .ng-leave .ng-leave-active ngRe

angularjs animation

http://augus.github.io/ngAnimate/ http://www.nganimate.org/angularjs/ng-repeat/move http://codepen.io/ShMcK/pen/kHxKy http://codepen.io/kevinsmets/pen/rznBj

[CSS3 Animation] TweenMax.staggerTo()

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Hello Greensock!</title> <link href='http://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>

[AngularJS] TweenList 3D + AngularJS Animate

AngularJS animations and TweenLite make it really easy to create cool 3d effects in your application. <!DOCTYPE html> <html ng-app="helloGreensock"> <head lang="en"> <meta charset="UTF-8"> <title>