js代码
<script> $(function(){ var a = $('#nav'), b =a.offset(); $(document).on('scroll',function(){ var c = $(document).scrollTop(); if(b.top<=c){ a.css({'position':'fixed','top':'0px'}) }else{ a.css({'position':'absolute','top':'300px'}) } }) }) </script>