Last active
December 14, 2015 16:39
-
-
Save sndyuk/5116771 to your computer and use it in GitHub Desktop.
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
(function($) { | |
$.fn.noClickDelay = function() { | |
var $wrapper = this; | |
var $target = this; | |
var moved = false; | |
$wrapper | |
.bind( | |
'touchstart mousedown', | |
function(e) { | |
e | |
.preventDefault(); | |
moved = false; | |
$target = $(e.target); | |
if ($target.nodeType == 3) { | |
$target = $($target | |
.parent()); | |
} | |
$target | |
.addClass('pressed'); | |
$wrapper | |
.bind( | |
'touchmove mousemove', | |
function( | |
e) { | |
moved = true; | |
$target | |
.removeClass('pressed'); | |
}); | |
$wrapper | |
.bind( | |
'touchend mouseup', | |
function( | |
e) { | |
$wrapper | |
.unbind('mousemove touchmove'); | |
$wrapper | |
.unbind('mouseup touchend'); | |
if (!moved | |
&& $target.length) { | |
$target | |
.removeClass('pressed'); | |
$target | |
.trigger('click'); | |
$target | |
.focus(); | |
} | |
}); | |
}); | |
}; | |
})($); |
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
$('#hoge').noClickDelay(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
スワイプかクリックかの判定の待ち時間を切って、すべてクリック扱いにしているのでクリック後の反応が早くなる。なので、そのINPUTフィールドの上でスクロールできない。