我继续在我的主页未捕获的TypeError:使用此代码无法读取属性'top'of null 时出现错误。
// Load Carousel on Scroll.
$(window).scroll(function () {
$loadedContainer = $('.pane-idevels-browse-genres-custom-content-load .pane-content');
offsetY = $loadedContainer.offset().top;
cH = $loadedContainer.outerHeight();
wH = $(window).height();
bodyScroll = $('body').scrollTop();
htmlScroll = $('html').scrollTop();
scrollTop = (bodyScroll == 0) ? htmlScroll : bodyScroll;
carouselOffset = offsetY + cH;
windowOffset = wH + scrollTop;
if (carouselOffset <= windowOffset) {
loadCarouselGenres($loadedContainer)
}
})
答案 0 :(得分:0)
也许jQuery找不到本节中的元素
$('.pane-idevels-browse-genres-custom-content-load .pane-content');
答案 1 :(得分:0)
试试这个:
$(window).scroll(function () {
$loadedContainer = $('.pane-idevels-browse-genres-custom-content-load .pane-content');
if($loadedContainer){
offsetY = $loadedContainer.offset().top;
cH = $loadedContainer.outerHeight();
wH = $(window).height();
bodyScroll = $('body').scrollTop();
htmlScroll = $('html').scrollTop();
scrollTop = (bodyScroll == 0) ? htmlScroll : bodyScroll;
carouselOffset = offsetY + cH;
windowOffset = wH + scrollTop;
if (carouselOffset <= windowOffset) {
loadCarouselGenres($loadedContainer)
}
}
});