getBoundingClientRect()

componentDidMount() {

  const loadMoreFn = this.props.loadMoreFn

  const wrapper = this.refs.wrapper

  let timeoutId

  function callback(){

    const top = wrapper.getBoundingClientRect().top

    console.log(top)

    const windowHeight = window.screen.height

    if(top && top<windowHeight) {

        //  当 wrapper 已经被滚动到可视范围内了

        loadMoreFn()

    }

  }

  window.addEventListener('scroll', function() {

    if(this.props.isLoadingMore) {

      retrun

    }

    if(timeoutId) {

        clearTimeout(timeoutId)

    }

    timeoutId = setTimeout(callback, 50)

  }, bind(this), false)

猜你喜欢

转载自blog.csdn.net/qq_33834489/article/details/80033451
今日推荐