网页滚动悬浮固定JS特效

<style>
.rg_fixed {position: fixed;width:100%;bottom:80px;_position:absolute;_bottom:auto;_top:expression(eval(document.documentElement.scrollTop)+3);}
</style>
 
//滚动顶部判断
<script>
var bdggrgtop=$(".Footer-top").offset().top;
$(window).scroll(function(){console.log($(this).scrollTop());
if($(this).scrollTop()<bdggrgtop){
$('#test2').addClass('rg_fixed')
}else{
$('#test2').removeClass('rg_fixed');
}
});
</script>
 
//滚动底部判断
<script>
$(function($) {
var ttop=$("#test3").offset().top;
var theight=$("#test3").height(); console.log(theight);
var ttop2=$("footer").offset().top;
var theight2=$("footer").height();
 
$(window).scroll(function(){
if($(this).scrollTop()+$(window).height()<(ttop2+theight-40)){
$('#test3').addClass('rg_fixed')
}else{
$('#test3').removeClass('rg_fixed');
}
});
});
</script>

 

你可能感兴趣的