Jquery mobile iOS中的jQuery Mobile tap和taphold敏感性问题
在我的jQuery移动应用程序中,我想使用点击和点击保持事件。我尝试使用将事件处理程序绑定到这些事件的标准方法,但在taphold事件的情况下,tap事件始终处于触发状态,因此我使用了我在stackoverflow上发现的以下方法:Jquery mobile iOS中的jQuery Mobile tap和taphold敏感性问题,jquery-mobile,Jquery Mobile,在我的jQuery移动应用程序中,我想使用点击和点击保持事件。我尝试使用将事件处理程序绑定到这些事件的标准方法,但在taphold事件的情况下,tap事件始终处于触发状态,因此我使用了我在stackoverflow上发现的以下方法: $(“#list li”).live('vmousedown-vmouseup',函数(事件) { 如果(event.type==“vmousedown”) { tapTime=newdate().getTime(); } 其他的 { //event.type=
$(“#list li”).live('vmousedown-vmouseup',函数(事件)
{
如果(event.type==“vmousedown”)
{
tapTime=newdate().getTime();
}
其他的
{
//event.type==“vmouseup”
//在这里,您可以检查“点击”的时间长短,以确定您要做什么
持续时间=(新日期().getTime()-tapTime);
//tap代码
如果(持续时间>250&&持续时间=750){
}
现在,在装有iOS 5的iPhone上,我遇到了一个问题,即触发了点击事件,并且在向下滚动列表时选择了一个项目。我试图增加点击事件的持续时间,但在iOS中似乎没有效果。有什么建议吗?[已尝试并测试]
我检查了jQuery Mobile的实现。他们每次在“vmouseup”上的“taphold”之后都会触发“tap”事件
如果触发了“taphold”,解决方法是不触发“tap”事件。创建自定义事件或根据需要修改源,如下所示:
$.event.special.tap = {
tapholdThreshold: 750,
setup: function() {
var thisObject = this,
$this = $( thisObject );
$this.bind( "vmousedown", function( event ) {
if ( event.which && event.which !== 1 ) {
return false;
}
var origTarget = event.target,
origEvent = event.originalEvent,
/****************Modified Here**************************/
tapfired = false,
timer;
function clearTapTimer() {
clearTimeout( timer );
}
function clearTapHandlers() {
clearTapTimer();
$this.unbind( "vclick", clickHandler )
.unbind( "vmouseup", clearTapTimer );
$( document ).unbind( "vmousecancel", clearTapHandlers );
}
function clickHandler( event ) {
clearTapHandlers();
// ONLY trigger a 'tap' event if the start target is
// the same as the stop target.
/****************Modified Here**************************/
//if ( origTarget === event.target) {
if ( origTarget === event.target && !tapfired) {
triggerCustomEvent( thisObject, "tap", event );
}
}
$this.bind( "vmouseup", clearTapTimer )
.bind( "vclick", clickHandler );
$( document ).bind( "vmousecancel", clearTapHandlers );
timer = setTimeout( function() {
tapfired = true;/****************Modified Here**************************/
triggerCustomEvent( thisObject, "taphold", $.Event( "taphold", { target: origTarget } ) );
}, $.event.special.tap.tapholdThreshold );
});
}
};