2017-03-22 73 views
0

我想给头体的作用就像这个网站preview.oklerthemes.com/?theme=PortoCSS组合固定不跳的效果

使用的相对位置(以显示滚动)...和使用固定..但是当我把固定的位置,我看到这到了原来的位置,然后出现。 - >https://jsfiddle.net/uxhgpz6e/2/

enter

所以,我想避免这种 “跳效应”,但仍使用相对+固定。

+0

的[如何阻止内容跳起来使用jQuery背后固定NAV]可能的复制(http://stackoverflow.com/questions/42953618/how-to-stop-content-jumping-up-behind-fixed-nav-using-jquery) –

回答

0

更改您的滚动值,它应该得到你想要的行为:See this fiddle

$(window).scroll(function(){ 

     if($(window).scrollTop() > 100){ 
       $('.header-body').css('position','fixed').css('top','-100px'); 
     } else { 
      $('.header-body').css('position','relative').css('top','0'); 

     }  
}); 
+0

我想在确定的余量后仍然使用relative + fixed,所以我可以在www.preview中生成效果。 oklerthemes.com/?thethe=Porto网站的标题正文 – July

+0

我看到了,我已经编辑了我的答案 –

+0

我可以建议你添加'position:sticky',然后使用脚本作为回退 – LGSon