Skip to content

Instantly share code, notes, and snippets.

@mrjumpy
Last active September 3, 2015 10:10
Show Gist options
  • Save mrjumpy/28379c03836a8f20bb60 to your computer and use it in GitHub Desktop.
Save mrjumpy/28379c03836a8f20bb60 to your computer and use it in GitHub Desktop.

Angular 1.X 提供directive讓我們可以自訂屬性。 Angular 2. 的話。 大家可以先參考以下,稍微感覺一下我們可能會怎麼在它上面開發, 其實也是會有地方讓plugin去實作。 https://egghead.io/lessons/angular-2-angular-2-custom-events-es5

Angular 1.x 實作的方式可以是以下:

angular.module('myApp.directives', [])
       .directive('onTap', function () {
         return function (scope, element, attrs) {
           return $(element).hammer({
             prevent_default: false,
             drag_vertical: false
           })
             .bind("tap", function (ev) {
               return scope.$apply(attrs['onTap']);
             });
         };
       });

然後使用上可以變成:

       <button on-tap="DoAngularMethod()">Tap me</button>

所以,作成jquery plugin的方式,看起來滿正確的 此外 找了目前angular touch的實作方式 https://github.com/angular/bower-angular-touch/blob/master/angular-touch.js

有些地方滿值得之後可能可以參考,比如說:

            var TAP_DURATION = 750; // Shorter than 750ms is a tap, longer is a taphold or drag.
            var MOVE_TOLERANCE = 12; // 12px seems to work in most mobile browsers.
            var PREVENT_DURATION = 2500; // 2.5 seconds maximum from preventGhostClick call to click
            var CLICKBUSTER_THRESHOLD = 25; // 25 pixels in any dimension is the limit for busting clicks.

以上

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment