滑动窗口滚动条触发事件

$(window).on("scroll", function() {
if (timer) {
clearTimeout(timer);
timer = null;
}

timer = setTimeout(function() {
var st = $(window).scrollTop();
$("#imgbox").css('top',st+"px"); //弹出窗
if(st>240){
$(".infoimg").each(function(i){var src =$(this).attr("_src"); $(this).attr('src',src); $(this).removeAttr("_src");});
}

var offsetTop = st - scrollTop;
if (offsetTop > 0 && st > topBarHeight) {
topBar.css("top", -topBarHeight);
} else {
topBar.css("top", 0);
}

scrollTop = st;

timer = null;
}, 300);

});

原文地址:https://www.cnblogs.com/linjinzhuang/p/6289278.html