0

我有一些示例代码,我试图在导航到达某个点时使其保持粘性。问题是滚动方法一直在触发,它似乎卡在某种循环中,在这种循环中,不断地添加和删除类,使 flickr 变得粘滞。因此我的计算如下:

Stickme {

  constructor(cfg) {
        this.win = $(window);
        this.nav = $('.nav');
        this.setListeners();
  }

    setListeners () {
        this.win.scroll (() =>  {   
            this.debouncedScrollPage = debounce(this.scrollme, 3000);
            this.debouncedScrollPage();
            });
    }


    scrollme() {
        let total = this.nav.offset().top
            if ((total) < this.win.scrollTop()) {
                this.nav.addClass('nav--sticky');
            }else {
              this.nav.removeClass('nav--sticky');
            }
    }
    }
4

0 回答 0