AngularJSAngularJS1.X攻笔记13-动画以及触摸

  本文主要干了ngAnimation和ngTouch模块,自由男人张嘴的可比少,估计如为此之时候还要进一步系统的修一下。

一、安装

  AngularJS 1

   没错,就是酱紫。

仲、玩玩动画

  

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
    <meta charset="UTF-8">
    <title>route test</title>
    <style type="text/css">
        .ngFadeIn.ng-enter{
            transition: .3s linear all;
            opacity: 0;
            background: red;
        }
        .ngFadeIn.ng-enter-active{
            background: white;
            opacity: 1;
        }
    </style>
</head>
<body ng-controller="getCtrl">
    <h1>This is fixed part</h1>
    <ul>
        <li><a href="./">home</a></li>
        <li><a href="./#!/page1/{{1}}">page1</a></li>
        <li><a href="./#!/page2/{{2}}">page2</a></li>
        <li><a href="./#!/page3/{{3}}/我是一个小傻瓜/乌拉啦五">page3</a></li>
    </ul>
    <div>参数id为:{{id || "unknown"}}</div>
    <div>参数data为:{{data || "unknown"}}</div>
    <div ng-view class="ngFadeIn"></div>
    <script type="text/javascript" src="../node_modules/angular/angular.min.js"></script>
    <script type="text/javascript" src="../node_modules/angular-route/angular-route.min.js"></script>
    <script type="text/javascript" src="../node_modules/angular-animate/angular-animate.min.js"></script>
    <script type="text/javascript">
        angular.module("myApp",['ngRoute','ngAnimate'])
        .factory('serv',function(){
            return {
                log:function(){
                    return "hello";
                }
            };
        })
        .config(function($routeProvider,$locationProvider){
            $routeProvider
            .when("/page1/:id",{
                templateUrl:"./1.html"
            })
            .when("/page2/:id",{
                templateUrl:"./2.html"
            })
            .when("/page3/:id/:data*",{
                templateUrl:"./3.html",
                controller:"page3Ctrl",
                resolve:{
                    data:function(serv){
                        return serv.log();
                    }
                }
            })
            .otherwise({
                templateUrl:"./home.html"
            });
        })
        .controller("getCtrl",function($location,$routeParams,$scope,$route){
            $scope.show = function(){
                alert("我是index里边的控制器");
            }
            $scope.$on("$routeChangeSuccess",function(){
                if($location.path().indexOf("/page")==0){
                var id = $routeParams["id"];
                var data  = $routeParams['data'];
                $scope.id = id;
                $scope.data = data;
                }
            })
        })
        .controller('page3Ctrl',function($scope,data){
            $scope.show = function(){
                alert("我是page3的控制器");
            }
            console.log(data);
        })
    </script>
</body>
</html>

  这是一个要命可恶的卡通,但是她确实动了。这里先了解一下Angular发生提供动画支持,后面看官方文档学习一下。

老三、触摸事件

  

<!DOCTYPE html>
<html lang="en" ng-app='myApp'>
<head>
    <meta charset="UTF-8">
    <title>touch</title>
    <style type="text/css">
        div{
            width: 300px;
            height: 300px;
            background: red;
        }
    </style>
</head>
<body>
    <div ng-controller='touchCtrl' ng-swipe-right="handler('ffffffff')">

    </div>



    <script type="text/javascript" src="../node_modules/angular/angular.min.js"></script>
    <script type="text/javascript" src="../node_modules/angular-touch/angular-touch.min.js"></script>
    <script type="text/javascript">
        var myApp = angular.module("myApp",['ngTouch']);
        myApp.controller('touchCtrl',function($scope){
            $scope.handler = function(e){
                console.log(e);
            }

        })
    </script>
</body>
</html>

  我尝试获得事件对象然而落不交,太奇怪矣,过几上研究一下。

  这有的任意男人说的无比简单了,这远不够啊!过几天研究一下,说的钻得会研究之。

  完!吃饭去了!

  

相关文章