jQuery顶部浮动代码

2019PHP高薪工程师学习路线图....>>>

<script type="text/javascript">
  var margintop = $("#header").offset().top
 
  //var marginleft = $("#header_cont").offset().left;
 //alert(margintop)
 //alert(marginleft)
  
   $(window).scroll(function() {
     var scrtop = $(document).scrollTop();
     if(scrtop<margintop){
      $('#header').css({
          position: 'absolute',
          top: margintop,
          left:'0'
        });
 
      return false;
    }
        $('#header').css({
          position: 'absolute',
          top: scrtop,
          left:'0'
        });
    });
</script>