angularjs - Angular/CSS - 动态添加新元素时动画移动内容

标签 angularjs css ionic-framework css-transitions ng-animate

Angular 动画菜鸟在这里。

我可以使用 ngAnimate 成功地将内容动画化到页面上。然而,当我的新内容滑入时,它下面的所有内容都会跳到新位置。同样,当删除新内容时,以下内容会跳回。是否有 Angular 的方式来为以下内容的新位置设置动画?

<button class="button" ng-if="typingResponse">
    Submit!
</button>
<div class="response-section">
  <label class="item item-input item-stacked-label">
    <span class="input-label">Response</span>
    <textarea></textarea>
  </label>
</div>


.button.ng-enter {
  -webkit-animate: slideInLeft 1s;
  animation: slideInLeft 1s;
}
.button.ng-leave {
  -webkit-animate: slideOutLeft 1s;
  animation: slideOutLeft 1s;
}

enter image description here

最佳答案

@klauskpm 让我完成了大部分工作,this blog post是缺失的部分。

解决方案:

  1. 将按钮放在 div 中
  2. 设置div的初始max-height0px
  3. 在 div 的 max-height 属性上指定过渡
  4. 当要显示按钮时,增加div的max-height属性

更新代码:

<div class="button-container" ng-class="{'has-button': typingResponse}">
  <button class="button" ng-if="typingResponse">
    Submit
  </button>
</div>
<div class="response-section">
  <label class="item item-input item-stacked-label">
    <span class="input-label">Response</span>
    <textarea></textarea>
  </label>
</div>

.button.ng-enter {
  -webkit-animate: slideInLeft $slide-dur;
  animation: slideInLeft $slide-dur;
}
.button.ng-leave {
  -webkit-animate: slideOutLeft $slide-dur;
  animation: slideOutLeft $slide-dur;
}


.button-container {
  max-height: 0px;
  transition: max-height $slide-dur linear;
  -webkit-transition: max-height $slide-dur linear;
}

.button-container.has-button {
  max-height: 100px;
}

关于angularjs - Angular/CSS - 动态添加新元素时动画移动内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36162462/

相关文章:

android - 键盘遮挡了输入文本区域

python - flask Python : Accept data from Ionic app into flask

javascript - 无法禁用简单的 a 标签

javascript - 如何使图像宽度与屏幕宽度相同

一列两行的 CSS 以及带有 flexbox 的 sibling (就像贝宁的国旗!)

html - CSS 显示 :inline is not working

cordova - 如何查看添加的人行横道版本?

javascript - DIV 上的 ng-blur

javascript - 当我更改 AngularJS 中另一个选择选项的值时,如何更改选择选项的值?

html - html表格中列的固定宽度