简体   繁体   English

需要帮助使我的HTML和CSS代码更有效地导航

[英]Need help making my HTML and CSS code for navigation effect more efficient

$(document).ready(function(){       
    $("#sticky-header").hide();
});   

$(window).scroll(function(){
   if( $(document).scrollTop() > 160 ) {
      $.fx.speeds._default = 300;
      $('#sticky-header').show();
      $("#sticky-header").transition({ y: 60 });
   } else {
      $.fx.speeds._default = 0;
      $('#sticky-header').clearQueue().transition({ y: 0 });
      $('#sticky-header').hide();
   }
});

Here's my code: http://jsfiddle.net/de74ezo5/ 这是我的代码: http : //jsfiddle.net/de74ezo5/

I am trying to slide a new navigation down when scrolling past the top header, and then hide it when returning. 我试图在滚动到顶部标题上方时将新的导航向下滑动,然后在返回时将其隐藏。 Is there a more efficient way to do this? 有没有更有效的方法可以做到这一点? Possibly with CSS transitions? 可能是CSS过渡? My method appears clunky and inefficient to me. 我的方法对我来说显得笨拙且效率低下。 The animation tends to be jumpy sometimes. 动画有时容易跳动。

You can try to use jQuery .animate() and some easing. 您可以尝试使用jQuery .animate()和一些缓动。

$(window).scroll(function(){
   if( $(document).scrollTop() > 160 ) {

       $("#header").stop(true,false).animate({top:"-160px"}, 700, "easeInOutQuart")  
       $("#sticky-header").stop(true,false).animate({top:"0px"},700, "easeInOutQuart")  


   } else {

        $("#header").stop(true,false).animate({top:"0px"},1000, "easeInOutQuart")  
        $("#sticky-header").stop(true,false).animate({top:"-100px"},1000, "easeInOutQuart")  

   }
});

Here is the example: http://jsfiddle.net/9c56n442/1/ 这是示例: http : //jsfiddle.net/9c56n442/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM