简体   繁体   English

如何从iOS野生动物园的touchmove事件中检测滚动画布

[英]How to detect scrolling canvas from touchmove event in IOS safari

I am trying to detect scroll canvas from touchmove event its working fine on all except safari browser, In safari pageY, screenY coordinates of touchmove event are not properly working. 我正在尝试从touchmove事件检测滚动画布,使其在safari浏览器之外的所有浏览器上都能正常工作,在safari pageY中,touchmove事件的screenY坐标无法正常工作。 When I touch and move to down then coordinates (pageY,screenY) value fluctuates, means it's going like 468,473,470,480,477,486,481, It should be consistent, increasing or decreasing so I can detect scroll top or scroll down. 当我触摸并向下移动时,坐标(pageY,screenY)值会波动,这意味着它会变成468,473,470,480,477,486,481,它应该是一致的,增加或减少的,以便我可以检测到滚动顶部或向下滚动。 please help me out. 请帮帮我。

$scope.touchStart = function(e){
            var touchevent = e.originalEvent.changedTouches[0];
            tempMove = touchevent.screenY;
}

$scope.touchMove = function(e) {
            var touchevent = e.originalEvent.changedTouches[0];
            var currentY = touchevent.screenY;
            if(tempMove == 0){
                tempMove = currentY;
            }else{
                var dist = tempMove - currentY;
                window.parent.postMessage(dist,'*');
                tempMove = currentY;
            }
        };

I got a css hack to over come this issue. 我遇到了一个CSS hack来解决这个问题。 I have added an overlay to the canvas on touchmove event and then it gets easily scroll. 我在touchmove事件上向画布添加了一个叠加层,然后可以轻松滚动。

HTML 的HTML

     <div id="overlay" ng-show="doubleTapEvent"> <!--  overlay for scroll -->
      <div id="text" > <span class="font-size-15-all" >Scroll up or down</span><br>
        <button class="btn btn_scroll prime_col_white font-size-15-all openSansSemiBold" ng-click="scroll_Off()">
            <span>Back to Label Maker</span>
        </button>
      </div>
    </div><!--  end overlay for scroll -->
   <div class="col-xs-12 col-sm-12 col-md-12  no-padding main_canvas_wrapper" ng-touchmove="touchMove($event)">
     <canvas id="canvasArea" width="400" height="400"></canvas>  
   </div>

Controller 控制者

        $scope.touchMove = function(e) {
            e.preventDefault();
            var tObj = canvas.getActiveObject();
            if(!tObj){
                $scope.doubleTapEvent = true;
            }
        };
        $scope.scroll_Off = function(){
            $scope.doubleTapEvent = false;
        }

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

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