【发布时间】:2017-06-06 19:46:49
【问题描述】:
增加图像大小的 CSS 过渡效果,但不适用于减小图像大小。有人知道怎么解决吗?
var app = angular.module('myApp', ['ngAnimate']);
app.controller('myController', function($scope){
$scope.myImgClass = 'start-class';
});
app.animation('.fadeOut', function(){
return {
enter: function(element, parentElement, afterElement, doneCallback){},
leave: function(element, doneCallback){},
move: function(element, parentElement, afterElement, doneCallback){},
addClass: function(element, className, done){
jQuery(element).animate({ opacity: 0 }, 3000);
},
removeClass: function(element, className, done){
jQuery(element).animate({ opacity: 1 }, 3000);
}
};
});
.shrink-add, .shrink-remove{
-webkit-transition:all ease 2.5s;
-moz-transition:all ease 2.5s;
-o-transition:all ease 2.5s;
transition:all ease 2.5s;
}
.shrink,
.shrink-add.shrink-add-active{
height: 100px;
}
.start-class,
.shrink-remove.shrink-remove-active{
height: 400px;
}
<!doctype html>
<html ng-app="myApp">
<head>
<title>AngularJS $animate Service</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<link rel="stylesheet" href="/css/animate.css">
</head>
<body>
<div ng-controller="myController">
<h3>Image Animation</h3>
<input type="button" ng-click="myImgClass='shrink'" value="Small"/>
<input type="button" ng-click="myImgClass=''" value="Big"/>
<hr>
<img ng-class="myImgClass" src="http://vriz.net/vriz/nma/ch25/static/images/arch.jpg"/>
</div>
<script src="http://code.angularjs.org/1.2.9/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.9/angular-animate.min.js"></script>
</body>
</html>
【问题讨论】:
-
您的代码似乎无法正常工作,但基于此,我最好的预感是您应该尝试将过渡添加到实际图像,而不是添加到图像上的类触发按钮点击。
标签: css angularjs css-transitions