由於某些原因,單擊文檔在Chrome中不起作用(closeQuickView未被調用)。event.stopPropagation()在使用jQuery 1.7時不能在chrome中工作
這些元件經由AJAX加載並因此需要有。對()動作(先前.live(),其現在已經過時在jQuery 1.7)
這裏使用給出的示例:How do I detect a click outside an element?作爲基礎
$('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>
數字被封裝在AJAX加載的主題#content div中。我添加了一個內部包裝div,清除了緩存,它現在似乎正在工作:S – Craig