Skip to content

Instantly share code, notes, and snippets.

@sndyuk
Last active December 14, 2015 16:39
Show Gist options
  • Save sndyuk/5116771 to your computer and use it in GitHub Desktop.
Save sndyuk/5116771 to your computer and use it in GitHub Desktop.
(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();
}
});
});
};
})($);
$('#hoge').noClickDelay();
@sndyuk
Copy link
Author

sndyuk commented Mar 8, 2013

スワイプかクリックかの判定の待ち時間を切って、すべてクリック扱いにしているのでクリック後の反応が早くなる。なので、そのINPUTフィールドの上でスクロールできない。

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