AngularJS animate image on src change

前端 未结 8 2242
一整个雨季
一整个雨季 2020-12-30 09:26

I have an AnuglarJS app, where I load/change some images from a webservice...

Controller

.controller(\'PlayerCtrl\', function($scope, programService         


        
8条回答
  •  误落风尘
    2020-12-30 10:12

    My solution to this problem is to watch for changes on ng-src and using a timeout function to add a class which does the fadeIn effect.

    HTML

    
    

    Angular Code

    .directive('fadeIn', function($timeout){
        return {
            restrict: 'A',
            link: function($scope, $element, attrs){
                $scope.$watch('selectedFormat.name', function(newValue, oldValue) {
                    if(newValue!=oldValue) {
                        $element.removeClass("ng-hide-add");
                        $element.addClass("ng-hide-remove");
                        $timeout(function () {
                            $element.addClass("ng-hide-add");
                        }, 100);
                    }
                })
            }
        };
    })
    

    CSS

    .animate-show.ng-hide-add, .animate-show.ng-hide-remove {
            display: inline-block !important;
        }
        .animate-show.ng-hide-add.ng-hide-add-active, .animate-show.ng-hide-remove {
            opacity: 0;
        }
        .animate-show.ng-hide-add{
          transition: all linear 0.7s;
        }
        .animate-show.ng-hide-add, .animate-show.ng-hide-remove.ng-hide-remove-active {
            opacity: 1;
        }
    

提交回复
热议问题