【发布时间】:2014-01-25 07:04:12
【问题描述】:
我正在创建一个 Angular 服务,它将一个简单的通知框附加到 DOM 并显示它,而无需添加 HTML 代码并编写逻辑以在必要时隐藏和显示它。
该服务名为 $notify,使用如下:
$notify.error( "this is an error", {position: "bottom-left"} );
该服务将使用 angular.element 构建通知框并将其添加到 DOM。所有这一切都很好。但是,我也使用 ngAnimate 和 animate.css 让通知在显示时顺利滑入并在关闭时滑出。我已经验证,如果我只是将通知 HTML 代码粘贴到我的页面中,动画就可以工作,但当通过服务动态添加代码时,这些动画将无法工作。项目是否必须在文档加载时位于 DOM 中才能使 ngAnimate 工作?我已验证 Angular 服务已加载并正确插入 HTML 代码,但未应用任何动画。这是 HTML 和 CSS 的样子。
HTML:
<div class="simple-notify simple-notify-top-left simple-notify-info" ng-if="toggle">
<simple-notify-header>Hello!<span class='simple-notify-dismiss pull-right' ng-click='doSomething()'>×</span></simple-notify-header>
<simple-notify-body>Some bogus text here!</simple-notify-body>
</div>
CSS/LESS:
.simple-notify {
&.ng-enter {
display:none;
animation: @animate-enter @animation-length;
-webkit-animation: @animate-enter @animation-length;
}
&.ng-enter-active {
display:block;
}
&.ng-leave {
animation: @animate-leave @animation-length;
-webkit-animation: @animate-leave @animation-length;
}
}
谢谢!!!
【问题讨论】:
标签: javascript jquery html css angularjs