【问题标题】:How do I slide a div and all of its contents using ngAnimate?如何使用 ngAnimate 滑动 div 及其所有内容?
【发布时间】:2015-11-16 00:59:13
【问题描述】:

我拥有的是一个带有列表和一些选择的“索引”页面,然后是右侧的屏幕外 div,其中包含特定于当前选择的内容(“显示”页面的缩写)。单击按钮时,我希望屏幕上的 div 的“索引”一半滑出视图,而 div 的“显示”一半滑入视图(因此整个 div 向左滑动)。

为了在 jQuery 中执行此操作,作为一种临时解决方法,我编写了以下内容:

slideInContent = function () {
    $('#main')
        .animate({'margin-left':'-=100vw'}, 500, 'linear');

},
backToCover = function () {
    $('#main')
        .animate({'margin-left':'+=100vw'}, 500, 'linear');
},

HTML:

<div id='main'>
  <div id='index'>
    ...
  </div>
  <div id='show'>
    ...
  </div>
</div>

CSS:

#index {
  float: left;
}

#show {
  width: 100vw;
  height: auto;
  margin-left: 50%;
  display: inline-block;
}

#main {
  width: 200vw;
  overflow-y: scroll;
}

我如何用 Angular 做到这一点(我想它会在某个地方的 ngAnimate 模块中)。

【问题讨论】:

    标签: javascript angularjs fullscreen slide ng-animate


    【解决方案1】:

    我就是这样做的,你需要ngRoutengAnimate。我也用过BootstrapAnimate.css

    我们使用 CSS 为视图设置动画,就像 .ng-enters 视图和 .ng-leaves 一样。

     <style>
      .main-view.ng-enter,
      .main-view.ng-active {
       animation: slideInRight 1s ease;
       -webkit-animation: slideInRight 1s ease;
       -moz-animation: slideInRight 1s ease;
       -o-animation: slideInRight 1s ease;
      }
    
      .main-view.ng-leave {
       display: none;
      }
     </style>
    

    HTML

    <body ng-app="storeApp" ng-controller="StoreCtrl">
    
     <section id="store">
    
      <div class="col-xs-3" id="store-categories">
         <a ng-repeat="category in categories" class="btn btn-default btn-block" ng-href="#{{category}}">{{category}}</a>
      </div><!-- end col-xs-3 -->
    
      <div class="overflow-wrapper">
       <div class="col-xs-9" id="store-items">
        <div class="main-view" ng-view></div>
       </div><!-- end store-items -->
      </div>
    
     </section><!-- end store -->
    
     <!-- Vendor JS -->
     <script src="vendors/angular.min.js"></script>
     <!-- Deps -->
     <script src="vendors/angular-animate.min.js"></script>
     <script src="vendors/angular-route.min.js"></script>
    
     <!-- App.js -->
     <script>
      angular.module('storeApp', ['ngAnimate', 'ngRoute'])
    
      .config(['$routeProvider', function($routeProvider) {
       $routeProvider
    
       .when('/', {
        redirectTo: '/category1'
       })
    
       .when('/category1', {
        templateUrl: 'js/views/category-1/index.html',
        activetab: 'category1'
       })
    
       .when('/category2', {
        templateUrl: 'js/views/category-2/index.html',
        activetab: 'category2'
       })
    
      }])
    
      .controller('StoreCtrl', ['$scope', function($scope) {
    
       $scope.categories = ['category1', 'category2'];
    
      }]);
     </script>
    
    </body>
    

    【讨论】:

    • 这并不能完全理解我的意思。 #main 是一个包含 #index#show 的 div。 #index div 的宽度和高度为 100vw/vh,#show div 也是如此。 #show 从屏幕外开始,但是当用户单击选择时,#index 页面会明显更新其背景(将其视为封面),#show 会无形更新其内容。当用户点击按钮时,#main 向左滑动隐藏#index 并显示#show
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多