这个就是类似lazy load的需求,绑定scroll事件,判断块的top和窗口的scrolltop和height的关系。
参考: Load (Lazy Loading) a Div whenever the DIV gets visible for the first time
参考: Load (Lazy Loading) a Div whenever the DIV gets visible for the first time
var b2Offset = $('#block2').offset();
$(window).scroll = function(){
if($(this).scrollTop() >= b2Offset.top){
//do something
}
}很简单的一个问题嘛,页面滚动的时候判断scrollTop,再获取到区块2具体页面顶部的距离借助JQ的offset方法可以直接获取到。