jQuery--在x(像素)滚动后滚动到id

时间:2016-09-18 21:30:06

标签: jquery html scroll

通过修改下面的代码,滚动了多个像素(并且下面的div不向上滚动)后是否可以滚动到#id?

  template <template <typename...> class C = EdgeSensor>
  std::enable_if_t<
     true == chkTplInL<C, SensorType...>::value> localEdges ()
   { this->saveEdges(); std::cout << "localEdges case A" << std::endl; }

  template <template <typename...> class C = EdgeSensor>
  std::enable_if_t<
     false == chkTplInL<C, SensorType...>::value> localEdges ()
   { std::cout << "localEdges case B" << std::endl; }

  template <typename B = TrendSensor>
  std::enable_if_t<
     true == std::is_base_of<B, BaseSensor>::value> localTrends ()
   { this->saveTrends(); std::cout << "localTrends case A" << std::endl; }

  template <typename B = TrendSensor>
  std::enable_if_t<
     false == std::is_base_of<B, BaseSensor>::value> localTrends ()
   { std::cout << "localTrends case B" << std::endl; }

});

1 个答案:

答案 0 :(得分:0)

这不是最后一个解决方案,但这可以帮助您完成第一步:

$(document).ready(function(){
  var numberOfPixels = 20;
  var lastScrollTop = 0;
  $(window).scroll(function(event){
    var st = $(this).scrollTop();
    if (st > lastScrollTop){
       // downscroll code
       if($(window).scrollTop() > numberOfPixels) {
         $('html, body').animate({
           scrollTop: $("#someid").offset().top
         }, 2000);
         //$(window).off('scroll');
       }
    } else {
      // upscroll code
    }
   lastScrollTop = st;
  });
});