jquery - iScroll 冲突

标签 jquery ipad iscroll

iPad 上 Mobile Safari 中的 HTML5 模板。带 iScroll 的 Div 工作正常。 if/else 语句中还包含一个 jQuery 函数。该函数测试用户是否在 iScroll div 外部点击,如果是,则淡出 iScroll div。
问题是,如果用户在页面上的第二个 div 之外点击,则 if/else 语句作为测试工作正常,但如果用户在 iScroll div 之外点击,则 if/else 语句无法作为测试工作。不明白为什么,已经尝试了 if/else 语句中与 iScroll div 关联的所有 div ID,但没有效果。
功能如下:

var articleBodyEl = document.getElementById('content');
articleBodyEl.addEventListener("touchend", function() {
var $target = $(event.target);
if ($target.is('ul#article_images') || $target.is('ul#article_images li') || $target.is('div#article')) {
    //do nothing
} else {
    $('#article').fadeToggle('fast');
}
});

#article = iScroll div

#article_images = 页面上的单独 div,测试用户在该 div 外部单击是否正常。
HTML:

<div id="article">
<div id="article_content">
   <div id="scroller">
   <div id="text_1" class="article_text">
    <h4>Wish you were here</h4>
    <p>Sometimes we stumble upon a photograph that requires no words whatsoever. An image that proves the ancient adage that a good picture is worth a thousand words (and probably more, if some of them are small words like ‘if’, ‘it’ and ‘er’). </p>
   </div>
   </div>
</div>
</div>

最佳答案

尝试用以下内容替换 if/else,

if (!$target.is('div#article')) { 
    $('div#article').fadeToggle('fast');
}

如果 content div 是 iScroll div 的父级,那么您可能必须在 iScroll 的 touchend 事件上停止传播。

关于jquery - iScroll 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8431059/

相关文章:

javascript - Jquery 附加 MVC PartialView 脚本

jquery - 滑动登录论坛的烦恼

iOS:iPad 的 Size Class 在 iOS 7.1 上不显示 View

iphone - 将 iPad xib 转换为 iPhone xib

javascript - Iscroll for bootstrap modal 在窗口调整大小后工作

android - iScroll 4 无法正常工作

javascript - 在 Bootstrap Datepicker 中设置最小日期

javascript - 在没有文本对齐中心的情况下将动画居中对齐

iphone - iOS Development : Why do I always get the "A connection failure occurred" on the 1st attempt, 但成功就下了吗?

javascript - 升级到 iScroll5 后,ios 上的 iScroll 无法使用