我有一个小脚本,它利用 jQuery Mobile 的 swipeleft
和 swiperight
事件来更改 div
元素内的文本。自从将各种Apple设备升级到iOS7后,它无法正常运行。
我设置了一个简单的 fiddle 来重现问题,here .
示例 jQuery
$('#container').on('swipeleft swiperight', '.score', function(e) {
$(this).text( parseInt($(this).text(), 10) + (e.type == 'swipeleft' ? -1 : +1) );
});
示例标记
<div id="container">
<div class="score">0</div>
<div class="score">0</div>
</div>
如果您在每个 div.score
上向左滑动
或向右滑动
多次,它就会开始表现不稳定,在事件会触发,有时它根本不会触发,直到您再次与屏幕交互(滚动/触摸等)
我很确定这不是我测试过的特定于单个设备的问题,并且在各种设备(2x iPhone 5s'、iPhone 5、iPhone 4、iPad 2nd gen 和 iPad 4th gen)上得到相同的结果)。
在升级到 iOS7 之前,这一切都完美无缺,我尝试搜索看看是否有其他人遇到过这个问题,或者看看它是否是 iOS7 中 Safari Mobile 的已知错误,但我找不到任何东西。
如果有人可以提供解释或可能的解决方案,我将不胜感激。
最佳答案
使用 setTimeout()
似乎可以解决问题:
$('#container').on('swipeleft swiperight', '.score', function(e) {
var $this = $(this);
setTimeout(function() {
$this.text( parseInt($this.text(), 10) + (e.type == 'swipeleft' ? -1 : +1) );
}, 0);
});
Some useful information can be found here
Here's a fiddle
关于jquery - iOS7 中 jQuery Mobile 滑动事件的不稳定行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19164002/