window.addEventListener('scroll',throttle(handleScroll,100));

let throttle_func = null

throttle(func,delay){

  var context = this

  return function(){

    var args = arguments

    if(!throttle_func){

      throttle_func = setTimeout(function(){

        func.apply(context,args)

        throttle_func = null

      })

    }

  }

}

 

handleScroll(){

  let offestTop =  this.$el.querySelector('#id').getBoundingClientRect().top //  元素距离页面顶部的距离

}

posted on 2020-01-20 15:53  仔仔爱学习  阅读(620)  评论(0编辑  收藏  举报