[英]jQuery pop-up not working on page with infinite scrolling
我有一個正在使用的網站,該網站上有一組產品(最初只有圖像),當您將鼠標懸停在它們上面時,它將顯示一個彈出窗口,其中包含項目詳細信息,“立即購買”按鈕等。
這一切都很好,除了當您向下滾動並無限滾動進入並加載另一組產品時,即使使用正確的javascript和css作為其上方的非無限產品,它也不會顯示彈出窗口。
我試圖解決此問題的方法:
我用於彈出窗口的代碼是:
var hideTimer = null;
var hoverElem = null;
function openFbox() {
$(this).attr('href', $(this).find('.quickview').attr('href'));
$.facebox({ div: $(this).attr('href') });
}
function closeFbox() {
if (hoverElem != 'facebox_overlay') {
// do nothing
} else {
hideTimer = setTimeout(function() {
if (hoverElem == 'facebox_overlay')
closeIt();
}, 750);
}
}
$(".thumbnail")
.hoverIntent({
sensitivity: 7,
interval:400,
timeout:0,
over: openFbox,
out: closeFbox
});
無限滾動的代碼是: https : //gist.github.com/rickydazla/1390610
吸引懸停偵聽器時,您需要使用jQuery方法.on()。 這會將偵聽器附加到DOM中的一個永久元素,但是要等待對指定子項執行的操作。
$("parentElementSelector").on("mouseenter", "targetSelector", function() {
$(this).attr('href', $(this).find('.quickview').attr('href'));
$.facebox({ div: $(this).attr('href') });
}).on("mouseleave", "targetSelector", function() {
if (hoverElem != 'facebox_overlay') {
// do nothing
} else {
hideTimer = setTimeout(function() {
if (hoverElem == 'facebox_overlay')
closeIt();
}, 750);
}
});
父對象可以是身體,目標可以是.thumbnail
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.