欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

基于Angular.js实现的触摸滑动动画实例代码

程序员文章站 2022-03-20 22:54:52
先上图: 这个主要用到是angular-touch.js中封装好的ng-swipe-left,ng-swipe-right,向左或向右的触摸事件。结合css3的tra...

先上图:

基于Angular.js实现的触摸滑动动画实例代码

这个主要用到是angular-touch.js中封装好的ng-swipe-left,ng-swipe-right,向左或向右的触摸事件。结合css3的transition实现的动画。ng-class为切换写好的动画的classname.

<!doctype html>
<html ng-app="myapp">
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8">
 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
 <title>angular2</title>
 <script type="text/javascript" charset="utf-8" src="angular.min.js"></script>
 <script type="text/javascript" charset="utf-8" src="angular-touch.min.js"></script>
 <style type="text/css">
 *{margin:0px;padding:0px;}
 .box{position:relative;left:0px;margin:10px 0px;width:100%;height:100px;background:red;transition:all .5s;;}
 .swipeleft{left:-100%;}
 </style>
 <script type="text/javascript" charset="utf-8">
 angular.module("myapp",["ngtouch"]).controller("controller",[function(){
 var self = this;
 self.swipeleft = function(){
 return (self.classname = "swipeleft");
 }
 }]);
 </script>
 </head>
 <body>
 <ul>
 <li ng-controller="controller as con" class="box box1" ng-swipe-left="con.swipeleft()" ng-class="con.classname"></li>
 <li ng-controller="controller as con" class="box box2" ng-swipe-left="con.swipeleft()" ng-class="con.classname"></li>
 <li ng-controller="controller as con" class="box box3" ng-swipe-left="con.swipeleft()" ng-class="con.classname"></li>
 <li ng-controller="controller as con" class="box box4" ng-swipe-left="con.swipeleft()" ng-class="con.classname"></li>
 </ul>
 </body>
</html>

以上所述是小编给大家介绍的基于angular.js实现的触摸滑动动画实例代码,希望对大家有所帮助