iOS上的JQuery Mouseup

我最近添加了jquery.mouse2touch.min.js插件到我的游戏中,经过testing,我遇到了一个问题。 我的运动系统由两个div组成(一个向左移动一个向右移动),基本上当你按住div时,玩家应该向一个方向移动,而当你放开时,他应该停止。 问题是,如果我压下太久,然后放手,玩家不会停下来。

这是让他感动的代码:

// iControl System var $div = $('#character'); $('#ios-left').mousedown(function(){ leftTimer = setInterval(function(){ processWalk('left'); },100); }).mouseup(function(){ $('#character').stop(); clearInterval(leftTimer); }).mouse2touch(); $('#ios-right').mousedown(function(){ rightTimer = setInterval(function(){ processWalk('right'); },100); }).mouseup(function(){ $('#character').stop(); clearInterval(rightTimer); }).mouse2touch(); 

和小提琴: http : //jsfiddle.net/gqfesrhw/

谢谢(如果有人认为这可能是一个与mouse2touch插件的问题,我会打开其他build议)

工作小提琴

定时器的问题,你应该移动之前清除时间间隔。 您的全局variablesTimerWalk with clearInterval(TimerWalk); 应该是有用的。

这是代码块

 $('#ios-left').mousedown(function () { clearInterval(TimerWalk); TimerWalk = setInterval(function () { processWalk('left'); }, 100); }).mouseup(function () { $div.stop(); clearInterval(TimerWalk); }).mouse2touch(); $('#ios-right').mousedown(function () { clearInterval(TimerWalk); TimerWalk = setInterval(function () { processWalk('right'); }, 100); }).mouseup(function () { $div.stop(); clearInterval(TimerWalk); }).mouse2touch(); 

这只适用于正确的移动,您可能需要解决其他问题。