javascript - 如何使用 ngAnimate 滑动 div 及其所有内容?

标签 javascript angularjs fullscreen slide ng-animate

我拥有的是一个“索引”页面,其中包含列表和一些选择,然后右侧有一个离屏 div,其中包含特定于当前选择的内容(简短的“显示”页面)。单击按钮时,我希望屏幕上 div 的“索引”部分滑出 View ,而 div 的“显示”部分滑入 View (因此整个 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 模块中的某个位置)。

最佳答案

这就是我的做法,您需要 ngRoutengAnimate。我还使用了 Bootstrap 和 Animate.css:

我们使用 CSS 为 View 添加动画效果,因为它 .ng-enters View 和 .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>

关于javascript - 如何使用 ngAnimate 滑动 div 及其所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32151205/

相关文章:

javascript - 使用对象而不是字符串进行 "to"时,React-router 重定向错误

javascript - 在 $Interval 上清除窗口对象

javascript - Cordova 输入类型数字 maxlength 在 android 中不起作用?

Javascript 全屏在 JSFiddle 中不起作用

javascript - 导轨 3 : How to trigger a form submission via javascript?

javascript - 为什么需要将 $(document).ready 添加到自执行函数中?

java - 如何让JFrame充满整个显示器屏幕?

jquery - 如何使英雄部分始终填满浏览器窗口?

javascript - Angular - 如何根据数组中的值检查复选框?

javascript - Mean.js 查询变量不起作用