Javascript 使用lodash updatePosition不起作用

Javascript 使用lodash updatePosition不起作用,javascript,jquery,css,jquery-animate,lodash,Javascript,Jquery,Css,Jquery Animate,Lodash,您好,我第一次使用lodash。我的jquery代码一直在跳转,我正试图在lodash函数中迁移它,但我真的不知道如何迁移 IDK如果这很重要,但代码背后的主要思想是让div向下滚动到某个位置并捕捉到某个位置,但它一直在跳跃。请告知 $(window).on('scroll', _.throttle(updatePosition, 100)); $(window).on('scroll', function(){ var scroll = $(window).scrollTop();

您好,我第一次使用
lodash
。我的
jquery
代码一直在跳转,我正试图在
lodash
函数中迁移它,但我真的不知道如何迁移

IDK如果这很重要,但代码背后的主要思想是让div向下滚动到某个位置并捕捉到某个位置,但它一直在跳跃。请告知

$(window).on('scroll', _.throttle(updatePosition, 100));

$(window).on('scroll', function(){
    var scroll = $(window).scrollTop();

    var sectionPosTop = document.getElementById('header-bamboo-scroll').getBoundingClientRect();

    var headerHeight = document.getElementById('header').getBoundingClientRect();


    if (scroll >= 660 && scroll <= 680 ) {
        console.log('greater than 660 and less than 680');
        $('html, body').animate({
            scrollTop: headerHeight.height
         }, 500, function() {
            $('html, body').stop();
         });
    }

 });
});
$(window).on('scroll',u.throttle(updatePosition,100));
$(窗口).on('scroll',function(){
var scroll=$(窗口).scrollTop();
var sectionPosTop=document.getElementById('header-bambol-scroll').getBoundingClientRect();
var headerHeight=document.getElementById('header').getBoundingClientRect();

如果(scroll>=660&&scroll我不太清楚您想要做什么,但是您可以使用
.throttle
在代码执行之间获得延迟,这可以给您一个平滑的动画。您可以调整延迟时间(以毫秒为单位)以获得您想要的

    var updatePosition = function() {
      var scroll = $(window).scrollTop();

      var sectionPosTop = document.getElementById('header-bamboo-scroll').getBoundingClientRect();

      var headerHeight = document.getElementById('header').getBoundingClientRect();


      if (scroll >= 660 && scroll <= 680 ) {
        console.log('greater than 660 and less than 680');
        $('html, body').animate({
          scrollTop: headerHeight.height
        }, 500, function() {
          $('html, body').stop();
        });
      }
    }

    $(window).on('scroll', _.throttle(updatePosition, 100));
var updatePosition=function(){
var scroll=$(窗口).scrollTop();
var sectionPosTop=document.getElementById('header-bambol-scroll').getBoundingClientRect();
var headerHeight=document.getElementById('header').getBoundingClientRect();
如果(滚动>=660&&滚动