Modifying DOM (slideDown/slideUp) with AngularJS and jQuery

后端 未结 2 1370
说谎
说谎 2021-02-02 12:29

I\'m trying to implement a slideDown/slideUp animation with AngularJS. I can\'t use CSS3\'s transition (unfortunately) since the height is set to auto

2条回答
  •  鱼传尺愫
    2021-02-02 12:31

    I want to show an example of how this is done with ng-if, since I was looking for a solution for hours running into multiple completely different approaches that work with ng-show only. You may use ng-if vs ng-show if say you need directives initialized only upon becoming visible.

    To use jQuery slideDown / slideUp with ng-if, you can also use ngAnimate but using different hooks: enter and leave.

    app.animation('.ng-slide-down', function() {
      return {
        enter: function(element, done) {
          element.hide().slideDown()
          return function(cancelled) {};
        },
        leave: function(element, done) { 
          element.slideUp();
        },
      };
    });
    
    
    I will slide down upon entering the DOM.

    This was surprisingly difficult to accomplish, even trying various JS based approaches and CSS only approaches. Ultimately there is a time and place for jQuery's animations.

提交回复
热议问题