页面滑动至某处,固定导航。
<div class="download">我是要固定的</div>
.download.fixed { overflow: hidden; position: fixed; width: 100%; top: 0; background: #fff; z-index: 998; }
var downLoadBar = $('.download'); var downSetTop = downLoadBar.offset().top; $(window).on('scroll', function() { var nowScroll = $(this).scrollTop() if(nowScroll > downSetTop) { downLoadBar.addClass('fixed') } else { downLoadBar.removeClass('fixed') } })