angular动画与jquery动画配合

前两个动画还是传统的css3类加载动画和和<code>css3@keyframes</code>动画,所以比较简单,看我上一篇文章有讲解。
jquery动画,无所谓就是三种形式,通过<code>css({key:value})</code>的形式,<code>animate({key:value})</code>的形式和<code>addClass("className")、removeClass("className")</code>三种形式,但是在angular中<code>addClass("className")、removeClass("className")</code>的形式是不行的,只可以通过在<code>animation(element,done)</code>函数中通过传递,<code>function(){}中利用
$(element).css({}) $(element).animate({})</code>并且支持jquery的链式语法,可以创作出很随意的动画

<!DOCTYPE html>
<html lang="en" ng-app="3APP">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="lib/angular.min.js" type="text/javascript"></script>
    <script src="lib/angular-route.js" type="text/javascript"></script>
    <script src="lib/jquery-2.1.4.min.js"></script>
    <script src="lib/bootstrap.js" type="text/javascript"></script>
    <script src="lib/angular-animate.js" type="text/javascript"></script>
    <link rel="stylesheet" href="../css/bootstrap.css" type="text/css"/>
    <style>
        .ng-bar{
            width: 1200px;
            height: 50px;
        }
        /*.animateView.ng-enter,.animateView.ng-leave{
            transition: 2s linear all;
            -webkit-transition: 2s linear all;
        }
        .animateView.ng-enter{
            width: 1000px;
            height: 500px;
            border: 1px solid blueviolet;
            margin: 0 auto;

        }
        .animateView.ng-enter-avtive{
            width: 1000px;
            height: 500px;
            border: 1px solid blueviolet;
            margin: 0 auto;
            font-size: 30px;
        }
        .animateView.ng-leave{
            width: 500px;
            height: 200px;
            border: 1px solid seagreen;
            margin: 0 auto;
            font-size: 10px;
        }
        .animateView.ng-leave{
            width: 500px;
            height: 200px;
            border: 1px solid skyblue;
            margin: 0 auto;
            font-size: 20px;
        }*/

        /*@keyframes animateView-enter {
            from{opacity: 0;color:red}
            to{opacity: 1;color: greenyellow}
        }
        @-webkit-keyframes animateView-enter {
            from{opacity: 0;color: red}
            to{opacity: 1;color: greenyellow}
        }
        @keyframes animateView-leave{
            from {opacity:1;color: #0000cc}
            to{opacity: 0;color: skyblue}
        }
        @-webkit-keyframes animateView-leave{
            from {opacity:1;color: #0000cc}
            to{opacity: 0;color: skyblue}
        }
        .animateView.ng-enter{
            -webkit-animation: 2s animateView-enter;
            animation: 2s animateView-enter;
        }
        .animateView.ng-leave{
            -webkit-animation: 2s animateView-leave;
            animation: 2s animateView-leave;
        }*/
        .animateView{
            border: 1px solid blue;
            width: 200px;
            position: relative;
        }
    </style>
</head>
<body ng-controller="routerController">
    <div class="ng-bar">
        <ul class="nav nav-tabs">
            <li><a href="#/">home</a></li>
            <li><a href="#/two">second view</a></li>
            <li><a href="#/three">third view</a></li>
        </ul>
    </div>
    <div class="animateView " ng-view>
    </div>
</body>
<script>
    var app=angular.module('3APP', ['ngAnimate', 'ngRoute']);
    app.controller('routerController', function () {

    });
    app.config(function($routeProvider) {
        $routeProvider.when('/', {
            template: '<h2>One</h2>'
        }).when('/two', {
            template: '<h2>Two</h2>'
        }).when('/three', {
            template: '<h2>Three</h2>'
        });
    });
    app.animation('.animateView', function () {
        return {
            enter: function (element, done) {
                $(element).css({
                    opacity: 0
                });
                $(element).animate({
                    opacity: 1,
                    left:'220px',
                    top:'200px',
                }, function () {
                    console.log("done")
                }).css({
                    color:'red',
                    background:'green'
                });
            },
            leave: function (element, done) {
               $(element).animate({
                   top:'20px',
                   left:'500px'
               }).css({
                   opacity:'0.5'
               });
            }
        }
    })

</script>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 原文链接 http://blog.poetries.top/2016/10/20/review-jQuery 关注...
    前端进阶之旅阅读 16,679评论 18 503
  • 1.JQuery 基础 改变web开发人员创造搞交互性界面的方式。设计者无需花费时间纠缠JS复杂的高级特性。 1....
    LaBaby_阅读 1,200评论 0 1
  • 1.JQuery 基础 改变web开发人员创造搞交互性界面的方式。设计者无需花费时间纠缠JS复杂的高级特性。 1....
    LaBaby_阅读 1,367评论 0 2
  • 一、样式篇 第1章 初识jQuery (1)环境搭建 进入官方网站获取最新的版本 http://jquery.co...
    凛0_0阅读 3,451评论 0 44
  • 如果可以 我愿意老成一座桥 割断了天与水的交界 连结着山与山的脉脉情诉 桥是摇晃着的路 我在桥头等过你 除却天边月...
    伊霏阅读 187评论 0 3