0
私はアンドロイドとIOSのダブルクリックを検出するためにjquery doubletap関数を使用します。このセレクタはダブルタッププラグインで動作しません
(function($){
// Determine if we on iPhone or iPad
var isiOS = false;
var agent = navigator.userAgent.toLowerCase();
if(agent.indexOf('iphone') >= 0 || agent.indexOf('ipad') >= 0){
isiOS = true;
}
$.fn.doubletap = function(onDoubleTapCallback, onTapCallback, delay){
var eventName, action;
delay = delay == null? 500 : delay;
eventName = isiOS == true? 'touchend' : 'click';
$(this).bind(eventName, function(event){
var now = new Date().getTime();
var lastTouch = $(this).data('lastTouch') || now + 1 /** the first time this will make delta a negative number */;
var delta = now - lastTouch;
clearTimeout(action);
if(delta<500 && delta>0){
if(onDoubleTapCallback != null && typeof onDoubleTapCallback == 'function'){
onDoubleTapCallback(event);
}
}else{
$(this).data('lastTouch', now);
action = setTimeout(function(evt){
if(onTapCallback != null && typeof onTapCallback == 'function'){
onTapCallback(evt);
}
clearTimeout(action); // clear the timeout
}, delay, [event]);
}
$(this).data('lastTouch', now);
});
};
})(jQuery);
モバイルでは、このコードを使用してイベントを発生させます。
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
$('#table1 tbody tr').doubletap(function() {
var href = $(this).attr("relationid");
alert(this);
if (href) {
window.location = 'details/?id=' + href;
}
});
}else{
$('#table1 tbody tr').click(function() {
var href = $(this).attr("relationid");
if (href) {
window.location = 'details/?id=' + href;
}
});
}
表の行は次のようになります
<tr class="test odd" relationid="1" role="row">
<td>1</td>
<td class="sorting_1">Testklant</td>
<td>90.00</td>
</tr>
問題)は(ダブルタップを使用する場合、relationid属性が選択されていないことです。 click()を使ってうまく動作します。
私はvar hrefに警告すると、「[object window]」と表示されます。
これを解決するには?
私はjquerymobileについてもこれらのバグを発見しました。だからこそ私のソリューションはjquery mobileを使わず、jqueryだけで十分です。 –
Fingerプラグインに切り替えました。今は素晴らしい作品です。 http://ngryman.sh/jquery.finger/ – Mbrouwer88