Different transitions with AngularJS

断了今生、忘了曾经 提交于 2020-01-11 10:46:09

问题


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?


回答1:


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

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>

Angular:

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;

}


来源:https://stackoverflow.com/questions/17108611/different-transitions-with-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!