AngularJS对SRC改变动画形象 [英] AngularJS animate image on src change
本文介绍了AngularJS对SRC改变动画形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个AnuglarJS的应用程序,在那里我加载/从web服务改变一些图片...
I have an AnuglarJS app, where I load/change some images from a webservice...
控制器
.controller('PlayerCtrl', function($scope, programService) {
....
programService.refresh(function(data) {
$scope.program = data;
});
....
模板
<img src="{{program.image}}" />
在从WebService我的应用程序的更新,预计图像的变化,我只想做一个淡出/淡入时发生这种情况,那怎么办呢?
When my app updates from the webservice the images changes as expected, I just want to make an fadeout / fadein when this happens, how can that be done?
是否有可能总是淡出/中时,图像的src改变?
Is it possible to always make a fadeout/in when a image src changes?
推荐答案
感谢您的答复 -
我落得这样做,它的作品;)
I ended up doing this, and it works ;)
--- ---指令
.directive('fadeIn', function($timeout){
return {
restrict: 'A',
link: function($scope, $element, attrs){
$element.addClass("ng-hide-remove");
$element.on('load', function() {
$element.addClass("ng-hide-add");
});
}
};
})
--- ---模板
--- Template ---
<img ng-src="{{program.image}}" class="animate-show" fade-in />
--- --- CSS
--- CSS ---
.animate-show.ng-hide-add, .animate-show.ng-hide-remove {
transition: all linear 0.5s;
display: block !important;
}
.animate-show.ng-hide-add.ng-hide-add-active, .animate-show.ng-hide-remove {
opacity: 0;
}
.animate-show.ng-hide-add, .animate-show.ng-hide-remove.ng-hide-remove-active {
opacity: 1;
}
这篇关于AngularJS对SRC改变动画形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文