iPad上Mobile Safari中的HTML5模板。带有iScroll的Div运行得很好。在if/else语句中还包含一个jQuery函数。该函数测试用户是否在iScroll分区之外点击,如果是,则淡出iScroll分区。
问题是,如果用户在页面上的第二个div之外点击,if/else语句可以很好地作为测试,但如果用户在iScroll div之外点击,则不能作为测试。找不到原因,我已经尝试了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');
}
});#文章= iScroll目录
#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>发布于 2012-04-08 17:53:07
尝试将if/else替换为以下内容,
if (!$target.is('div#article')) {
$('div#article').fadeToggle('fast');
}如果content div是iScroll div的父目录,那么您可能必须在iScroll的touchend事件上执行stopPropagation。
https://stackoverflow.com/questions/8431059
复制相似问题