event.stopPropagation()在使用jQuery 1.7的chrome中不起作用 [英] event.stopPropagation() not working in chrome with jQuery 1.7
本文介绍了event.stopPropagation()在使用jQuery 1.7的chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
出于某种原因,单击该文档在Chrome中无效(未调用closeQuickView)。
For some reason clicking the document isn't working in Chrome (the closeQuickView is not being called).
元素是通过AJAX加载的,因此需要有.on()动作(以前的.live()现已弃用 jQuery 1.7 )
The elements are loaded via AJAX and so need to have .on() action (previously .live() which is now deprecated in jQuery 1.7)
使用此处给出的示例:如何检测元素外部的点击?作为基础
Used the example given here: How do I detect a click outside an element? as a basis
$('html').on('click', '.poster:not(.active) .image-effect', function (event) {
var obj = $(this).parent();
// If there are no .close spans
if (obj.find('.close').length === 0) {
// Add the close element by javascript to remain semantic
obj.find('.quick-view').append('<span class="close">×</span>');
}
// Close any open Quick Views
closeQuickView();
// Add the active class (controls opacity)
obj.addClass('active');
// Fade in the Quick View
obj.find('.quick-view').fadeIn(200, 'easeInOutQuint');
event.preventDefault();
event.stopPropagation();
});
$('html').on('click', '.active', function () {
return false;
});
$('html').on('click', '.close', function () {
closeQuickView();
});
$('html').on('click', '.quick-view', function (event) {
event.stopPropagation();
});
// Close the QuickView with a button
$('html').on('click', function () {
closeQuickView();
});
function closeQuickView() {
$('.poster').removeClass('active');
$('.quick-view').fadeOut(200, 'easeInOutQuint');
}
我的标记如下:
<figure class="grid_2 box poster">
<a class="image-effect" href="#">
<img class="colour" src="path/to/image" />
<img class="bw" src="path/to/image" />
</a>
<div class="quick-view">
Content
</div>
</figure>
推荐答案
尝试 event.stopImmediatePropagation
这篇关于event.stopPropagation()在使用jQuery 1.7的chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文