Last active
December 14, 2015 23:49
-
-
Save narusemotoki/5168786 to your computer and use it in GitHub Desktop.
スマートフォンなどでJavaScriptのクリックイベントが遅れるのを解消する(AngularJS)
nd-click="hoge($event)"としても、hogeの中で$eventを取得できません。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button nd-click="hoge()">ボタン</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment