jQuery监听滚动条事件,当滚动到页面顶部时,box平滑移动到固定位置。
$(window).scroll(function(e){
var top2= $(window).scrollTop();
if(top2<5){
$('.right_bl').css({'top':'150px',"transition":"1s"});
}else{
$('.right_bl').css({'top':'75px',"transition":"1s"});
}
});
监听层距离顶部某位置时,box平滑移动到固定位置。
document.body.onmousewheel = function() {
var box = document.getElementById("banner_ej");
var pos = box.getBoundingClientRect();
if(pos.bottom<165||pos.bottom<0){
$('.right_bl').css({'top':'75px',"transition":"1s"});
// console.log(pos.bottom)
}else{
$('.right_bl').css({'top':'150px',"transition":"1s"});
// console.log(pos.bottom)
}
}