本文介绍了如何将动画添加到angularjs uib-alert指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想为推入数组中的新警报添加淡入动画,并为已退出的警报添加淡入.

I want to add fade-in animation for new alerts pushed into array and fade-out for dismissed alerts.

5秒后自动关闭警报.

Alerts are dismissed automatically after 5 seconds.

我已经包含了angular-animate ui-bootstrapui-bootstrap-tpls库.

如何使这些动画正常工作?

How can i get these animations working?

请参阅演示: http://plnkr.co/edit/ecbCA7h2zVA4XnvUHfFX?p=preview

<html ng-app="myApp">

  <head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
    <script src="https://code.angularjs.org/1.5.0/angular-animate.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/ui-bootstrap.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/ui-bootstrap-tpls.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-controller="MainController">
    <h1>Alert With Animation</h1>
    <uib-alert
      ng-repeat="alert in alerts"
      type="{{alert.type}}"
      dismiss-on-timeout="5000"
      close="alerts.splice($index, 1);">{{alert.msg}}
    </uib-alert>
    <input type='text' ng-model='msg' />
    <button ng-click="addAlert(msg,'danger')">Add Alert</button>
  </body>

</html>

脚本

(function() {

  var app = angular.module("myApp", ['ui.bootstrap', 'ngAnimate']);

  app.controller("MainController", function($scope) {

    $scope.alerts = [];

    $scope.msg = "No Animation!";

    $scope.addAlert = function(msg, type) {
      $scope.alerts.push({
        msg: msg,
        type: type
      });
    };

  });

}());

推荐答案

答案基于Pankaj的评论.

Answer is based on Pankaj's comment.

引我这篇文章的人: http ://www.yearofmoo.com/2013/08/remastered-animation-in-angularjs-1-2.html

  • <uib-alert>..</uib-alert>元素中添加了class='repeat-item'.
  • 为动画效果添加了适当的样式.

  • added class='repeat-item' to <uib-alert>..</uib-alert> element.
  • added proper stylings for animation effects.

<style type="text/css">
.repeat-item.ng-enter,
.repeat-item.ng-leave {
  -webkit-transition: 0.5s linear all;
  transition: 0.5s linear all;
}

.repeat-item.ng-enter,
.repeat-item.ng-leave.ng-leave-active {
  opacity: 0;
}

.repeat-item.ng-leave,
.repeat-item.ng-enter.ng-enter-active {
  opacity: 1;
}
</style>

查看工作演示: https://plnkr.co/edit/CK2lV4mBVGs8q5gyYklE?p=preview

第一次单击添加警报时,没有淡入动画.之后,一切似乎都很好.

When you click to add an alert for the very first time, there is no fade-in animation. After that, everything seems OK.

这篇关于如何将动画添加到angularjs uib-alert指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:08