Skip to content

Instantly share code, notes, and snippets.

@narusemotoki
Last active December 14, 2015 23:49
Show Gist options
  • Save narusemotoki/5168786 to your computer and use it in GitHub Desktop.
Save narusemotoki/5168786 to your computer and use it in GitHub Desktop.
スマートフォンなどでJavaScriptのクリックイベントが遅れるのを解消する(AngularJS) nd-click="hoge($event)"としても、hogeの中で$eventを取得できません。
angular.module('AngularStudy', []).directive 'ndClick', => ($scope, $element, $attrs) =>
isTap = isTapped = false
$element.bind 'click', => $scope.$apply $attrs['ndClick'] unless isTapped
$element.bind 'touchstart', => isTap = true
$element.bind 'touchmove', => isTap = false
$element.bind 'touchend', => if isTap
isTapped = true
$scope.$apply $attrs['ndClick'], $element
<button nd-click="hoge()">ボタン</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment