当用户滚动到灰色区域下方时,我有一些jQuery触发控制台日志/混合面板跟踪事件,一个用于点击页面底部,另一个用于当用户滚动到页面顶部时。我可以在JSFiddle中触发控制台日志,但它不会发生在jsfiddle之外的实际页面中。
$(function () {
var $win = $(window);
$win.scroll(function () {
if ($win.scrollTop() == 0) {
console.log("USER SCROLLED TO TOP");
mixpanel.track(
"User Scrolled To Top", {
"url": window.location.href
});
} else if ($win.height() + $win.scrollTop() >= $('#top').height() - 0 && $win.height() + $win.scrollTop() <= $('#top').height() + 0) {
console.log("VIEWED BELOW THE FOLD");
mixpanel.track(
"User Scrolled Below the fold", {
"url": window.location.href
});
} else if ($win.height() + $win.scrollTop() == $(document).height()) {
console.log("USER SCROLLED TO BOTTOM");
mixpanel.track(
"User Scrolled To Bottom", {
"url": window.location.href
});
}
});
});
在开发工具中打开控制台以查看事件:USER SCROLLED TO TOP
,VIEWED BELOW THE FOLD
和USER SCROLLED TO BOTTOM
。完整代码在这里,而滚动功能来自第1-26行:
JSFIDDLE LINK
答案 0 :(得分:0)
我发现它实际上是一个css问题,在身体中使用了overflow-x: hidden;
。删除它允许滚动功能触发。