前兩個動畫還是傳統(tǒng)的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>函數(shù)中通過傳遞韩容,<code>function(){}中利用
$(element).css({}) $(element).animate({})</code>并且支持jquery的鏈式語法,可以創(chuàng)作出很隨意的動畫
<!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>