hap*_*400 5 css animation angularjs
我正在尝试构建应该隐藏的动画垂直面板
当用户单击按钮时,面板应从右侧滑动。这是我的代码:
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>
Run Code Online (Sandbox Code Playgroud)
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;}
}
Run Code Online (Sandbox Code Playgroud)
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'
};
});
Run Code Online (Sandbox Code Playgroud)
问题:
加载时滑动面板可见一秒钟然后隐藏
(示范)
将不胜感激任何建议
您可以使用jQueryslideUp或尝试自定义 Angular 指令,例如AngularSlideables。但您也可以将直接 CSS 与 AngularngAnimate模块一起使用,如下所示:
.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;
}
Run Code Online (Sandbox Code Playgroud)
然后简单地定义你的面板:
<div class="panel panel-primary panelAnimate">...</div>
Run Code Online (Sandbox Code Playgroud)
在您的具体情况下,您可能会使用 CSSanimate而不是transition我上面使用的 CSS。