不同的过渡与AngularJS [英] Different transitions with AngularJS

查看:181
本文介绍了不同的过渡与AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能实现与AngularJS不同的转换。可以说,我在我的web应用程序侧边栏。我的用户点击一个按钮X,侧边栏应该消失速度非常快,如果用户点击另一个按钮,侧边栏应该消失缓慢。

How can I enable different transitions with AngularJS. Lets Say, I have a sidebar in my web application. I the user clicks a button X, the sidebar should disappear very fast, if the user clicks another button, the sidebar should disappear slow.

我想,这将通过设置一个过渡期权价值的点击,然后改变侧边栏的可见性状态(在过渡指令观看)一个接工作。

I think, this would work by setting a transition option value after one of that clicks and then changing the visibility state of the sidebar (watched by the transition directive).

但是,这似乎有点像不好的风格适合我。有没有做到这一点的常用方法?

But that seems a bit like bad style for me. Is there a common way to do this?

推荐答案

我会做这样的事情。设置侧边栏默认过渡,然后申请一类具有不同的转换速度。

I would do something like this. Set a default transition for the sidebar, and then apply a class with a different transition speed.

下面是我的意思一个的jsfiddle:

Here is a jsFiddle of what I mean:

http://jsfiddle.net/rd13/eTTZj/149/

HTML

<div ng-controller="myCtrl">
    <div class="sidebar" ng-class="{'slide-out':boolChangeClass}">
        Sidebar
    </div>
    <button ng-click="click()">Toggle Sidebar</button>
</div>

角:

function myCtrl($scope) {
    $scope.click = function() {
        $scope.boolChangeClass = !$scope.boolChangeClass;
        $scope.$apply();
    }
}

CSS:

.sidebar {
    -moz-transition: left .1s;
    -webkit-transition: left .1s;
    -o-transition: left .1s;
    transition: left .1s;
    width: 100px;
    background-color: blue;
    position: absolute;
    top: 0px;
    bottom: 0px;
    left: -100px;
}

.slide-out {
    -moz-transition: left 1s;
    -webkit-transition: left 1s;
    -o-transition: left 1s;
    transition: left 1s;
    left: 0px;

}

这篇关于不同的过渡与AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆