简体   繁体   English

角度动画

[英]Angular Animations

After taking a break from Angular, I've decided to jump back onto the bandwagon.在从 Angular 休息一下之后,我决定重新加入这个潮流。 I'm currently working on a relatively small project to help me get used to the framework in full, and I've found myself stuck.我目前正在从事一个相对较小的项目,以帮助我完全适应该框架,但我发现自己陷入了困境。

I've read over and over that using jQuery with AngularJS is forbidden taboo, though I can't necessarily comprehend how to do the following purely in AngularJS,我一遍又一遍地读到,在 AngularJS 中使用 jQuery 是被禁止的禁忌,尽管我不一定完全理解如何在 AngularJS 中执行以下操作,

controller.js控制器.js

(function(){

    angular.module('app')
        .controller('homeCtrl', ['cache', 'page', '$scope', function(cache, page, $scope) {
            page.title.set('Home');
            if( !cache.getKey('welcomed') ) {
                $( "#welcome-message" ).fadeTo( 3000 , 0, function() {
                    $( "#welcome-message" ).hide();
                    $( "#after-welcome" ).show();
                    $( "#after-welcome" ).fadeTo( 2500 , 100 );
                    // cache.setKey('welcomed', true);
                });
            } else {
                $( "#welcome-message" ).hide();
                $( "#after-welcome" ).show();
                $( "#after-welcome" ).fadeTo( 2500 , 100 );
            }
        }]);

})();

As can be seen, I simply want to fade out of a welcome message and into the main content.可以看出,我只是想淡出欢迎信息并进入主要内容。 I know of ngAnimate, though I'm still a novice.我知道 ngAnimate,虽然我还是个新手。 My question standing is -- is there any simple way to accomplish what I've done above without the use of jQuery?我的问题是——有没有什么简单的方法可以在不使用 jQuery 的情况下完成我在上面所做的工作?

Using jQuery in AngularJS is not a forbidden taboo.在 AngularJS 中使用 jQuery 并不是禁止的禁忌。 Using jQuery to manipulate DOM in controllers is.使用 jQuery 在控制器中操作 DOM 是。 You can use jQuery in directives or in animations.您可以在指令或动画中使用 jQuery。 For example ( demo ):例如(演示):

myModule.animation('.show-hide-animation', function() {
  return {
    beforeAddClass : function(element, className, done) {
      if(className == 'ng-hide') {
        element.fadeTo(2500, 0, function() {
          done();
        });
        return function() {
          element.css('opacity', null);
        }
      } else {
        done();
      }
    },

    removeClass : function(element, className, done) {
      if(className == 'ng-hide') {
          element.fadeTo( 3000 , 0, function() {
            element.fadeTo( 2500 , 1, function() {
              done();
            });
          });      
        return function() {
          element.css('opacity', null);
        }
      } else {
        done();
      }
    }
  }
});

You can read more on javascript / jquery animations in:您可以在以下位置阅读有关 javascript / jquery 动画的更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM