如何处理角度移动中的长按事件?

时间:2016-06-14 10:22:00

标签: javascript angularjs mobile cross-platform

我希望通过移动设备实现带角度的简单长按(长按)事件。

Live code

正在使用

  1. Chrome - 桌面
  2. Chrome移动检查员
  3. 没有工作

    1. iOS(chrome / safari) - 真实设备
    2. Android(Chrome) - 真实设备
    3. HTML

      {ado.Branch Name}

      JAVASCRIPT

      respond_to do |format|
        format.json  { render :json => {:ola_booking => @ola_booking, 
                                        :ola_products => @ola_products }}
      end
      

      CSS

      <div class="container-fluid" ng-app="app" ng-controller="MainCtrl">
        <center>
          <h3 ng-bind="test"></h3>
          <div class="box noselect"
               on-long-press="itemOnLongPress()"
               on-touch-end="itemOnTouchEnd()">
            <span>Document</span>
          </div>
        </center>
      </div>
      

1 个答案:

答案 0 :(得分:5)

您需要使用touchstarttouchend代替Long Press in JavaScript?

$elm.bind('touchstart', function(evt) {
    // Locally scoped variable that will keep track of the long press
    $scope.longPress = true;

    // We'll set a timeout for 600 ms for a long press
    $timeout(function() {
        if ($scope.longPress) {
            // If the touchend event hasn't fired,
            // apply the function given in on the element's on-long-press attribute
            $scope.$apply(function() {
                $scope.$eval($attrs.onLongPress)
            });
        }
    }, 600);
});

$elm.bind('touchend', function(evt) {
    // Prevent the onLongPress event from firing
    $scope.longPress = false;