我正在制作在线产品网站,我正在触发一个滚动事件,开始时只会显示 12 个元素,但是当第 8 个元素滚动到顶部时,滚动事件应该只运行一次,但每次向下滚动时它都会运行,请帮忙. 这是我的代码:
var navigation_offset_top = $('.prods-list li:nth-child(4)').offset().top;
$(window).on("scroll",function(){
var scroll_top = $(window).scrollTop(); // current vertical position from the top
// if scrolled more than the navigation, change its position to fixed to stick to top, otherwise change it back to relative
if (scroll_top > sticky_navigation_offset_top)
{
console.log("Hi");
}
});