AngularJS: ngTouch 300ms Delay

前端 未结 3 1133
有刺的猬
有刺的猬 2020-12-23 00:03

This Plunkr has 2 links. The one on the left side is using the ng-click directive with the on angular-touch module inserted. As said in the angular touch module description

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 00:34

       // Evita doble tap en dispositivos mobiles
        var TIME_BETWEEN_CLICK = 0;
        App.directive('ngSubmit', function () {
          return {
            restrict: 'A',
            replace: false,
            link: function (scope, el, attrs) {
              el.bind('submit', function (e) {
                if ((new Date().getTime() - TIME_BETWEEN_CLICK) > 300) {
                  TIME_BETWEEN_CLICK = new Date().getTime();
                } else {
                  e.stopImmediatePropagation();
                }
              });
            }
          };
        });
    
        App.directive('ngClick', function () {
          return {
            restrict: 'A',
            replace: false,
            link: function (scope, el) {
              el.bind('click', function (e) {
                if ((new Date().getTime() - TIME_BETWEEN_CLICK) > 300) {
                  TIME_BETWEEN_CLICK = new Date().getTime();
                } else {
                  e.stopImmediatePropagation();
                }
              });
            }
          };
        });
    

提交回复
热议问题