简体   繁体   English

离子离子滚动滚动父页面

[英]ionic ion-scroll scroll parent page

I am developing an app that looks like this: http://codepen.io/anon/pen/vNOVvb 我正在开发一个看起来像这样的应用程序: http : //codepen.io/anon/pen/vNOVvb

I am using ion-scroll to do horizontal scroll for the list of images. 我正在使用ion-scroll对图像列表进行水平滚动。 ion-scroll works fine as what I wanted. 离子卷轴可以按我的要求正常工作。 But the problem is user can't do vertical scroll to the full page when dragging on the ion-scroll. 但是问题是,在离子卷轴上拖动时,用户无法垂直滚动到整页。

How can I get the parent page vertical scroll works on ion-scroll? 我怎样才能使父页面垂直滚动在ion-scroll上工作?

My sample code as on codepen.io: 我的示例代码在codepen.io上:

index.html 的index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <!-- ionic/angularjs js -->
    <link href="http://code.ionicframework.com/1.1.0/css/ionic.css" rel="stylesheet">
    <script src="http://code.ionicframework.com/1.1.0/js/ionic.bundle.js"></script>

    <!-- your app's js -->
    <!--<script src="js/app.js"></script>
    <script src="js/controllers.js"></script>-->
  </head>
  <body ng-app="starter">
    <ion-nav-view></ion-nav-view>

    <!-- MENU Template -->
    <script id="templates/menu.html" type="text/ng-template">
      <ion-side-menus enable-menu-with-back-views="false">
  <ion-side-menu-content>
    <ion-nav-bar class="bar-stable">
      <ion-nav-back-button>
      </ion-nav-back-button>

      <ion-nav-buttons side="left">
        <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
        </button>
      </ion-nav-buttons>
    </ion-nav-bar>
    <ion-nav-view name="menuContent"></ion-nav-view>
  </ion-side-menu-content>

  <ion-side-menu side="left">
    <ion-header-bar class="bar-stable">
      <h1 class="title">Left</h1>
    </ion-header-bar>
    <ion-content>
      <ion-list>
        <ion-item menu-close href="#/app/content1">
          Content 1
        </ion-item>
      </ion-list>
    </ion-content>
  </ion-side-menu>
</ion-side-menus>

    </script>


     <!-- Content1 Template -->
    <script id="templates/content1.html" type="text/ng-template">
      <ion-view view-title="Content 1">
  <ion-content>
    <ion-item>
      <div class="item-text-wrap mytitle">Title 1</div>  
      <ion-scroll direction="x" zooming="false">
          <div>
            <a class="foodImage" href="#"><div style="background-image: url(http://lorempixel.com/200/200/food?1)">     </div></a>
                <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?2)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?3)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?4)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?5)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?6)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?7)"></div></a>
        </div>
      </ion-scroll>

      <div class="item-text-wrap mytitle">Title 2</div>  
      <ion-scroll direction="x" zooming="false">
          <div>
            <a class="foodImage" href="#"><div style="background-image: url(http://lorempixel.com/200/200/food?1)">     </div></a>
                <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?2)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?3)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?4)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?5)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?6)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?7)"></div></a>
        </div>
      </ion-scroll>

      <div class="item-text-wrap mytitle">Title 3</div>  
      <ion-scroll direction="x" zooming="false">
          <div>
            <a class="foodImage" href="#"><div style="background-image: url(http://lorempixel.com/200/200/food?1)">     </div></a>
                <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?2)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?3)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?4)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?5)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?6)"></div></a>
            <a class="foodImage" href="#">      <div style="background-image: url(http://lorempixel.com/200/200/food?7)"></div></a>
        </div>
      </ion-scroll>
    </ion-item>
  </ion-content>
</ion-view>
    </script>



  </body>
</html>

CSS file CSS文件

.mytitle{
  margin-top:20px;
  margin-bottom:20px;
}
.foodImage {
        margin-right:10px;
}

.foodImage div{
            display: inline-block;
            width:200px;
            height: 200px;
}
.foodImage div img{
                height: 100%;
                width: 100%;
            }

Javascript: 使用Javascript:

angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider

    .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'templates/menu.html',
    //controller: 'AppCtrl'
  })

  .state('app.content1', {
      url: '/content1',
      views: {
        'menuContent': {
          templateUrl: 'templates/content1.html'
        }
      }
    })


  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/app/content1');
});

Just Add this piece of code in your controller. 只需将这段代码添加到您的控制器中即可。

.controller('sampleviewctrl') 

inject this two library in your controller $timeout, $ionicScrollDelegate 将这两个库注入到您的控制器$ timeout,$ ionicScrollDelegate中

$timeout(function(){                                
    var sv = $ionicScrollDelegate.$getByHandle('horizontal').getScrollView();

    var container = sv.__container;

    var originaltouchStart = sv.touchStart;
    var originalmouseDown = sv.mouseDown;
    var originaltouchMove = sv.touchMove;
    var originalmouseMove = sv.mouseMove;

    container.removeEventListener('touchstart', sv.touchStart);
    container.removeEventListener('mousedown', sv.mouseDown);
    document.removeEventListener('touchmove', sv.touchMove);
    document.removeEventListener('mousemove', sv.mousemove);


    sv.touchStart = function(e) {
    e.preventDefault = function(){}
    originaltouchStart.apply(sv, [e]);
    }

    sv.touchMove = function(e) {
    e.preventDefault = function(){}
    originaltouchMove.apply(sv, [e]);
    }

    sv.mouseDown = function(e) {
    e.preventDefault = function(){}
    originalmouseDown.apply(sv, [e]);
    }

    sv.mouseMove = function(e) {
    e.preventDefault = function(){}
    originalmouseMove.apply(sv, [e]);
    }

    container.addEventListener("touchstart", sv.touchStart, false);
    container.addEventListener("mousedown", sv.mouseDown, false);
    document.addEventListener("touchmove", sv.touchMove, false);
    document.addEventListener("mousemove", sv.mouseMove, false);
});

Html Page should be like this HTML页面应该是这样的

<ion-scroll  has-bouncing="false" direction="x" zooming="false" delegate-handle="horizontal">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM