//滚动条大于120px时,判断pc端的情况下,导航条固定定位 $(window).scroll(function(){ var viewWidth=$(document).width() var top=$(document).scrollTop(); if(viewWidth>=768&&top>=120){ $('.d_head_nav').css({ 'position':'fixed', 'top':"0px", "width":'100%' }) }else{ $('.d_head_nav').css({ 'position':'relative' }) } })