angularjs之插件ngRoute和ngAnimate
使用ngRoute和ngAnimate配合使用,可以实现页面切换的效果。
如果有使用过swiper,就知道这个效果是怎么样的。
代码:
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://cdn.bootcss.com/angular.js/1.3.0/angular.min.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0/angular-route.min.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0/angular-animate.js"></script>
<style>
body{
margin:0;
padding:0;
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
} #p01{
width: 100%;
height: 100%;
background: red;
}
#p02{
width: 100%;
height: 100%;
background: green;
}
#p03{
width: 100%;
height: 100%;
background: blue;
}
#p04{
width: 100%;
height: 100%;
background: pink;
}
#p05{
width: 100%;
height: 100%;
background: skyblue;
}
/*以下的ngAniamte插件的关键,因为它靠css来实现动画,
可以不编写js代码;
流程:
为动画的容器添加选择器:如.container
然后再这个选择器上实现动画
.ng-enter出现时的样式->>
(它们之间动画效果,需要自己去编写如添加过渡效果transition,在选择器上编写)
->>.ng-enter-active出现后的样式
.ng-leave离开时的样式-->>.ng-leave-active离开后的样式
这里ng-show无效
ng-if会移除dom,生成dom,而ng-show只是改变其display属性。
display来实现显示隐藏,在渲染过程中会对动画效果无效化
而它和ng-view,就无需添加这个指令,因为这个页面的切换也是动态删除和添加
*/
.container{
width: 100%;
height: 100%;
transition: 1s all;
position: absolute;
overflow: hidden;
}
.container.ng-enter{
left: 100%;
}
.container.ng-enter-active{
left:0%;
}
.container.ng-leave{
left: 0%;
}
.container.ng-leave-active{
left: -100%;
}
</style>
<script>
window.onload=function(){
document.body.style.width=view().w+"px";
document.body.style.height=view().h+"px";
}
// 全屏可视区的宽高
function view(){
return {w:document.documentElement.clientWidth,
h:document.documentElement.clientHeight};
}
</script>
</head>
<body>
<div ng-controller="myCon" class="wrap">
<!-- 使用锚点实现路径变换,哈希值 -->
<a href="#shouye">首页</a>
<a href="#ziyemian01">子页面01</a>
<a href="#ziyemian02">子页面02</a>
<a href="#ziyemian03">子页面03</a>
<a href="#ziyemian04">子页面04</a>
<!-- ng-view配合ngRoute一起使用,实现单页面效果 -->
<div class="container" ng-view ></div>
</div>
<script>
// 依赖注入插件ngAnimate,ngRoute
var myApp=angular.module("myApp",["ngAnimate","ngRoute"])
// 在配置中规定路由规则
.config(['$routeProvider',function($routeProvider){ $routeProvider
.when('/shouye',{
template : '<p id="p01">首页的内容</p>'
})
// 路由路径
.when('/ziyemian01',{
template : '<p id="p02">子页面01</p>'
})
// 路由路径
.when('/ziyemian02',{
template : '<p id="p03">子页面02</p>'
})
// 路由路径
.when('/ziyemian03',{
template : '<p id="p04">子页面03</p>'
})
// 路由路径
.when('/ziyemian04',{
template : '<p id="p05">子页面04</p>'
})
// 重定向路径,就是默认路径
.otherwise({
redirectTo : '/shouye'
}); }])
.controller("myCon",["$scope",function($scope){ }])
</script>
</body>
</html>
ngRoute方面的使用:传送门
ngAnimate和ng-repeat配合:
代码:
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://cdn.bootcss.com/angular.js/1.3.0/angular.min.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0/angular-animate.js"></script>
<style>
.listBox{
transition: all 1s;
}
.listBox.ng-enter{
opacity: 0;
}
.listBox.ng-enter-active{
opacity: 1;
}
.listBox.ng-leave{
display: none;
}
/*对所有元素同时应用,可能实际运用中需要有一个先后的渐变出现的效果,这时候可以设置ng-enter-stagger来实现.
*/
.listBox.ng-enter-stagger{
animation-delay:100ms;
}
</style>
</head>
<body>
<div ng-controller="myCon">
<!-- ng-keyup事件指令 -->
<input type="text" ng-model="text" ng-keyup="change(text)">
<ul>
<li class="listBox" ng-repeat="k in dataArr">{{k}}</li>
</ul>
</div>
<script>
var myApp=angular.module("myApp",["ngAnimate"])
.controller("myCon",["$scope","$http",function($scope,$http){
$scope.change=function(val){
// $http和JQ里的$.ajax()工具使用方式类似
$http({
// 跨域请求方式
method:"JSONP",
// 百度搜索,数据接口
url:"https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+val+"&cb=JSON_CALLBACK"
// 成功接受数据,第一个参数是数据(json格式)
// 这个函数可以接受四个参数,具体查看手册
}).success(function(data){
$scope.dataArr=data.s;
});
}
}])
</script>
</body>
</html>
ngAnimate简单的使用方式:
代码:
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="angularjs-v1.5.9.js"></script>
<script src="ngAnimate.js"></script>
<style>
.box{
width:100px;
height:100px;
background: red;
transition: 1s all;
}
.box.ng-enter{
opacity: 0;
}
.box.ng-enter-active{
opacity: 1;
}
.box.ng-leave{
opacity: 1;
}
.box.ng-leave-active{
opacity: 0;
}
</style>
</head>
<body>
<div ng-controller="myCon">
<!-- ng-model在复选框里使用时true,false值 -->
<input type="checkBox" ng-model="bTure">
<!-- 这里ng-show无效 -->
<!-- ng-if会移除dom,生成dom,而ng-show只是改变其display属性。 -->
<!-- display来实现显示隐藏,在渲染过程中会对动画效果无效化 -->
<div ng-if="bTure" class="box">{{bTure}}</div>
</div>
<script>
var myApp=angular.module("myApp",["ngAnimate"])
.controller("myCon",["$scope",function($scope){
$scope.bTure=true;
}])
</script>
</body>
</html>
其实这些都是简单的方式去使用插件,但由于他们配合起来使用就变复杂了一些。
angularjs之插件ngRoute和ngAnimate的更多相关文章
- AngularJS常用插件与指令收集
angularjs 组件列表 bindonce UI-Router Angular Tree angular-ngSanitize模块-$sanitize服务详解 使用 AngularJS 开发一个大 ...
- angularJS 常用插件指令
长时间没有登入博客园了,今天突然想了想,当初开这个的目的,其实就是为了记录你当下的一个状态和累计一些问题,所以记录这些还是很有意义,毕竟不是什么牛,靠脸又吃不饱的这个年代,需要留下一些东西给自己看也好 ...
- 转AngularJS路由插件
AngularJS学习笔记--002--Angular JS路由插件ui.router源码解析 标签: angular源码angularjs 2016-05-04 13:14 916人阅读 评论(0) ...
- AngularJs练习Demo17 ngRoute
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- AngularJS 路由:ng-route 与 ui-router
AngularJS的ng-route模块为控制器和视图提供了[Deep-Linking]URL. 通俗来讲,ng-route模块中的$routeService监测$location.url()的变化, ...
- AngularJS Best Practices: ngRoute
app/----- components/---------- users/--------------- controllers/-------------------- users.control ...
- AngularJs练习Demo16 ngRoute
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- angularjs上传图片插件使用
一. angurlajs 相关 远程 jar 包 https://code.angularjs.org/angular-1.0.1.min.js 二. 正文 1. html 部分 <!-- 需要 ...
- angularJS的插件使用
$uibModal&&$uibModalInstance $uibModal和$uibModalInstance是一款angularJS的弹窗控件,github地址 http://an ...
随机推荐
- Java程序,猜大小游戏
一个骰子,通常有1.2.3.4.5.6等6种点数.我们将1.2.3记作“小”,将4.5.6记作“大”.猜中显示“猜对了”,猜错记作“猜错了”之类的字样.本程序可以用Java实现. import jav ...
- 修改centos启动项
centos7下修改启动项在路径/etc/grub.d/文件路径下,修改完成之后需要运行命令 grub2-mkconfig --output=/boot/grub2/grub.cfg
- [POI2008]KLO && POC
题意:给定一个序列 s1, s2,...sn,以及一个k,求一个连续的k个数,把s[i]...s[i+k-1]变成一个数s',使得sigma(|s[j]-s'|)(i<=j<=i+k-1) ...
- Zookeeper初次使用
下面介绍Linux系统中Zookeeper的初次使用方法. 1.jdk安装和zookeeper下载 首先从jdk官网中下载jdk文件,然后将文件放在/usr/local/java目录下解压,并打开.b ...
- zabbix_agentd.conf文件说明
由于工作中经常接触到zabbix,所以将agent配置整理一下,方便日常查看. # This is a config file for the Zabbix agent daemon (Unix) # ...
- 网页版视频网站可以用html5来实现吗?
当然可以用html5来实现视频网站,而且html5的诞生完全符合了百度优化,百度蜘蛛对这类的网站友好度非常高,会尽量会给高的权重,但是现在很多做 这类网站的开发还是比较习惯用websocket,这个东 ...
- 蛙蛙推荐:快速自定义Boostrap样式
现在越来越多的网站使用Bootstrap,相信大家也审美疲劳了,所以我们要用Bootstrap的第一步就是先把顶部的导航栏来自定义一下. 我现在使用的是bootstrap3.0,顶部导航定义如下 &l ...
- libQtCassandra 0.5.0 发布
libQtCassandra 0.5.0 修复了 QCassandraRow::exists() 函数的问题,更新了 Thrift 库. libQtCassandra 是一个高级的 C++ 库用来访问 ...
- 分布式系统一致性问题和Raft一致性算法
一致性问题 一致性算法是用来解决一致性问题的,那么什么是一致性问题呢? 在分布式系统中,一致性问题(consensus problem)是指对于一组服务器,给定一组操作,我们需要一个协议使得最后它们的 ...
- [Asp.net 开发系列之SignalR篇]专题六:使用SignalR实现消息提醒
一.引言 前面一篇文章我介绍了如何使用SignalR实现图片的传输,然后对于即时通讯应用来说,消息提醒是必不可少的.现在很多网站的都有新消息的提醒功能.自然对于SignalR系列也少不了这个功能的实现 ...