【问题标题】:ion-scroll doesn't scroll verticallyion-scroll 不会垂直滚动
【发布时间】:2016-08-28 23:06:19
【问题描述】:

所以我在我的页面上添加了 2 个 ion-scroll。 示例代码在这里:http://codepen.io/anon/pen/QNNExR

第一个离子滚动正常,我可以左右滚动。

对于第二个离子滚动,其中有很多“测试”段落。我无法垂直滚动(顶部 - 底部)。一旦我比屏幕高度更远一点,它总是会反弹。

注意:我没有为离子滚动或离子滚动内的内容设置高度,因为高度不固定(例如:离子滚动高度取决于屏幕尺寸,应该填充屏幕高度和内容高度的其余部分取决于内容长度)

我做错了什么?谢谢。

<html ng-app="ionicApp">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <title>Ionic vertical and horizontal Scroll</title>

    <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
    <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>

  </head>
  <body ng-controller="MyCtrl">

    <ion-header-bar class="bar-positive">
      <h1 class="title">Ionic vertical and horizontal Scroll</h1>
     </ion-header-bar>

<ion-pane>
    <ion-content>
<div>
            <ion-scroll zooming="false" direction="x" scrollbar-x="false" scrollbar-y="false" has-bouncing="true" style="width: 100%;">
            123
            </ion-scroll>
    </div>

<div>
<ion-scroll zooming="false" direction="y" style="width: 100%; height: 100%">
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
</ion-scroll>
</div>
    </ion-content>
</ion-pane>

  </body>
</html>

【问题讨论】:

    标签: ionic-framework


    【解决方案1】:

    使用$ionicScrollDelegate$timeout 注入器将其添加到您的控制器中:

     $timeout(function(){
        //return false; // <--- comment this to "fix" the problem
        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);
      });
      $timeout(function(){
        //return false; // <--- comment this to "fix" the problem
        var sv = $ionicScrollDelegate.$getByHandle('horizontal2').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);
      });
    

    【讨论】:

    • 那么这有什么作用呢?只发布代码通常没有那么有用。发布解释通常是!
    • 将此代码添加到您的控制器中,离子开发人员知道这一点
    • 这不是解释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多