gpt4 book ai didi

jquery - iScroll 冲突

转载 作者:行者123 更新时间:2023-12-01 06:03:54 32 4
gpt4 key购买 nike

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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com