ngIf with ngAnimate - 动画期间重复的 HTML 内容
ngIf with ngAnimate - duplicated HTML content during the animation
我尝试做简单的角度动画。但是我有一个问题,当我快速单击按钮时(在动画完成之前),当我单击时会多次创建内容容器......
如何防止这种情况?我想在单击后停止动画,然后在同一个对象而不是新对象上启动动画?
吉斯菲德尔
.HTML
<div ng-app="test">
<div class="container" ng-controller="TestController as tCtrl">
<div class="row">
<div class="col-xs-12">
<a class="btn btn-default" ng-click="tCtrl.tt = 1"> 1 </a>
<a class="btn btn-default" ng-click="tCtrl.tt = 2"> 2 </a>
</div>
</div>
<div class="row">
<div class="col-xs-12 animate-if" ng-if="tCtrl.tt === 1">Chosen = 1</div>
<div class="col-xs-12 animate-if" ng-if="tCtrl.tt === 2">Chosen = 2</div>
</div>
</div>
</div>
.JS
var app = angular.module('test', ['ngAnimate']);
app.controller('TestController', function ($scope) {
this.tt = 1;
});
.CSS
.animate-if.ng-enter, .animate-if.ng-leave {
-webkit-transition: opacity 5.2s ease-in-out;
-moz-transition: opacity 5.2s ease-in-out;
-ms-transition: opacity 5.2s ease-in-out;
transition: opacity 5.2s ease-in-out;
}
.animate-if.ng-enter,
.animate-if.ng-leave.ng-leave-active {
z-index: 0;
opacity: 0;
}
.animate-if.ng-leave,
.animate-if.ng-enter.ng-enter-active {
z-index: 1;
opacity: 1;
}
编辑:
我确实将代码更改为使用 ngRoutes
和 ngView
而不是ngIf
但ngAnimate
的行为是相同的。我认为这可能是 Angular 中的一个错误,因为在控制台中我在 angular-animate 中.js在第 1348 行有错误undefined in not a function
,其中包含operation.cancel()
并且是:
forEach(animationsToCancel, function(operation) {
operation.cancel();
});
当您快速单击左侧菜单"仪表板"和"用户"时,您可以在此处看到完整的问题。
编辑2:
我现在正在使用的解决方案:
this.fn_change_view = function (str_view, $event) {
if (!this.contentStopAnim) {
this.contentStopAnim = true;
this.active_view = str_view;
$timeout(function () {
template.contentStopAnim = false;
}, 360);
} else {
$event.preventDefault();
}
};
我正在阻止在动画完成之前更改位置 href,但这不是我很高兴的解决方案......
您可以使用
ng-show
和关键帧进行动画处理。这是一个笨蛋。
分配 css 事件。
.ng-hide-add {
animation:0.1s keyFrameLeave ease;
}
.ng-hide-remove {
animation:0.5s keyFrameEnter ease;
}
注册关键帧
@keyframes keyFrameEnter {
0% {
transform: translate(0,100px);
opacity: 0;
}
100% {
transform: translate(0,0);
opacity: 1;
}
}
@keyframes keyFrameLeave {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
您的 html 将如下所示:
<button ng-click="front = !front">click to animate</button>
<div ng-show="front">Displayed</div>
你的 js
$scope.front = false;
相关文章:
- 如何根据html内容使用ng类-AngularJS
- JavaScript在其他页面上用html内容填充文本框
- Rails:如何在浏览器中显示动态html内容,而不会对其进行转义,也不会引起XSS攻击
- 使用javascript动态创建html内容/元素
- 无法将大型html内容POST到Chrome上的服务器
- 使用li元素的html内容更改该元素的背景
- 如何从ajax返回两个html内容
- jQuery获取子DIV的HTML内容
- HTML内容下推到固定背景图像下方
- 在angular中,使用ng repeat生成动态html内容
- 使用$watch更改html内容
- 如何使用window.showModalDialog()显示HTML内容
- 如何在使用 UIWebView 编辑 HTML 内容时正确调整输入语言更改 (LTR/RTL) 的文本对齐方式
- 获取垂直溢出容器的 html 内容
- 为数组中的每个项目追加 html 内容
- Dojo:在 iframe 加载时解析 HTML 内容
- 允许 Itemp 在 Enyo 中使用 HTML 内容
- 从选项卡中获取 HTML 内容
- 可以将HTML内容放在画布上(登录页)
- 只有当类是硬编码的时,才可以使用jQuery来显示/隐藏html内容