javascript - 使用 angularjs animate 动画 div

标签 javascript css angularjs angularjs-directive angular-ui-router

我正在使用 angularJs 1.2+ 和 angular ui 路由器。
我有一条包含 div 的路线。当进入那条路线时,出现了一个 div。我想为进入和离开的那个 div 添加一个动画,但我不知道该怎么做。
我不知道我是应该创建一个使用 $animate 的指令还是使用内置的 angular 指令。有什么建议吗?

最佳答案

有一个常见问题:

还有相关的example plunker .

Developer Guide / Animations 中所述,

它们的工作原理:

Animations in AngularJS are completely based on CSS classes. As long as you have a CSS class attached to a HTML element within your website, you can apply animations to it...

因此,通过这种方式我们可以创建一些与 ui-view 元素相关的 CSS 定义(在 plunker 中使用的类或属性) 和 ngAnimation 注入(inject)类:.ng-enter, .ng-leave..

来自与 plunker 相关的常见问题解答的片段

[ui-view].ng-enter, [ui-view].ng-leave {
  position: absolute;
  left: 0;
  right: 0;
    ...
    transition:all .5s ease-in-out;
    ...
}

[ui-view].ng-enter-active {
  opacity: 1;
  ...
  transform:scale3d(1, 1, 1);
  ...
}

[ui-view].ng-leave {
  opacity: 1; 
  ...
  transform:translate3d(0, 0, 0);
  ...
}

关于javascript - 使用 angularjs animate 动画 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24230091/

相关文章:

javascript - CSS scroll snap 延迟多长时间?

css - 无法在 GWT 的全屏 ScrollView 内的面板中获取正确的背景图像

javascript - AngularJS:为什么使用 ng-options 时 $element.find ('option' ) 返回一个空数组?

Javascript - 四子棋游戏验证

javascript - 加载远程 Service Worker,在不同的域中运行?

javascript - 有什么方法可以从 url 获取文件大小而不使用谷歌应用程序脚本下载它。?

javascript - openlayers 导入 map 与数组 map

javascript - 如何使用 javascript 获取元素形式值的数组?

javascript - AngularJS 指令使用参数运行回调

javascript - 具有动态选择字段的表单无法验证