jquery - iOS7 中 jQuery Mobile 滑动事件的不稳定行为

标签 jquery jquery-mobile ios7 swipe

我有一个小脚本,它利用 jQuery Mobile 的 swipeleftswiperight 事件来更改 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/

相关文章:

jquery - 停止动画然后重新启动它

jquery - Rails,单击时更改 HTML 元素的类属性

jQuery dataTables 标题最初不调整为列值,而是在拖动屏幕后调整

javascript - jQuery Mobile – 切换单选按钮的启用和禁用状态

javascript - JQuery Mobile 动态添加的页面没有主题

javascript - 单击单选按钮时显示文本框。我该怎么做呢?

javascript - 两个问题 : should I do client-side or server-side in terms of validation? 另外,我如何验证没有文本框为空白/无效...

ios - Swift:线程 1 信号 SIGABRT

ios - 在 Storyboard 中实现登录/注销的正确方法

ios - 继承 UITableViewCell 并在 iOS 中添加自己的功能