其他分享
首页 > 其他分享> > vue 滚动吸顶 + 限流

vue 滚动吸顶 + 限流

作者:互联网

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 //  元素距离页面顶部的距离

}

标签:function,vue,throttle,args,限流,func,var,null,吸顶
来源: https://www.cnblogs.com/ch-zaizai/p/12218299.html