Different transitions with AngularJS

前端 未结 1 1388
名媛妹妹
名媛妹妹 2021-01-22 16:20

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

相关标签:
1条回答
  • 2021-01-22 16:54

    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;
    
    }
    
    0 讨论(0)
提交回复
热议问题