角度动画滑动面板 - 在加载视图时显示第二个

时间:2014-07-24 08:57:42

标签: angularjs css3 animation

我正在尝试构建动画垂直面板,假设隐藏

当用户点击按钮时,-panel应从右侧滑动。 这是我的代码:

HTML:

<body ng-controller="Ctrll">
    <p style="color:#000;margin:0"><span>slide:</span>{{slide}} </p>


    <button ng-click="showAlerts()" style="float:left">
      click to toggle panel
    </button>
    <!--sliding panel directive-->
    <alerts-center></alerts-center>


    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/angular-animate/angular-animate.js"></script>
    <script src="js/index.js"></script>
</body>

CSS:

    body{
      background-color:#FFF;
      height:100%;
      width:100%;
      margin:0;
      color:#FFF;
      font-size:3em;
      line-height:100px;
      text-align:center;
      overflow:hidden;
    }



    .animate-slide {
      background:#30373f;
      position:absolute;
      width: 320px;
      height:100%;
      top: 0;
      right:0px;
    }

    .animate-slide.ng-hide-add,
    .animate-slide.ng-hide-remove {
     display:none;
      -webkit-transition:0.5s linear all;
      -moz-transition:0.5s linear all;
      -o-transition:0.5s linear all;
      transition:0.5s linear all;
    }

    .animate-slide.ng-hide-remove.ng-hide-remove-active {
      -webkit-animation:0.5s slide-left;
      animation:0.5s slide-left;
    }

    .animate-slide.ng-hide-add.ng-hide-add-active {
      -webkit-animation:0.5s slide-right;
      animation:0.5s slide-right;
    }

    .animate-slide.ng-hide {
      right:-320px;
      display:none;
    }

    /* Chrome, Safari, Opera */
    @-webkit-keyframes slide-left
    {
      0%   {right:-320px;}
      100%  {right:0;}
    }

    /* Standard syntax */
    @keyframes slide-left
    {
      0%   {right:-320px;}
      100%  {right:0;}
    }

    /* Chrome, Safari, Opera */
    @-webkit-keyframes slide-right
    {
      0%  {right:0;}
      100%   {right:-320px;}
    }
    /* Standard syntax */
    @keyframes slide-right
    {
      0%  {right:0;}
      100%   {right:-320px;}
    }

JS:

 angular.module("app",["ngAnimate"])
.controller("Ctrll",function($scope, $timeout){        
   $scope.showAlerts  = function($event) {

      $timeout(function(){        
         $scope.$broadcast('openAlerts');
      },1)
    }
})
.controller('alertsCtrl', function ($scope) {
    $scope.$on('openAlerts', function(event, args) {
        $scope.slide = !$scope.slide;
    });
})
.directive('alertsCenter', function () {
    return {
      templateUrl: 'alerts.html',
      replace:true,
      restrict: 'E',
      controller:'alertsCtrl'
    };
});

问题:

加载滑动面板一秒钟后可见,然后隐藏

demonstration

非常感谢任何建议

1 个答案:

答案 0 :(得分:0)

您可以使用jQueryslideUp或尝试自定义角色指令,例如AngularSlideables。但您也可以使用Angular的ngAnimate模块直接使用CSS,如下所示:

.panelAnimate {
    transition: all 5s linear;
    -moz-transition: all 5s linear; /* Firefox 4 */
    -webkit-transition: all 5s linear; /* Safari and Chrome */
    -o-transition: all 5s linear; /* Opera */
    -ms-transition: all 5s linear; /* Explorer 10 */
}
.panelAnimate.ng-hide {
    opacity: 0;
}

然后只需定义您的面板:

<div class="panel panel-primary panelAnimate">...</div>

在您的具体情况下,您可能会使用CSS animate而不是我上面使用的transition