2018-12-10

2018-12-10  本文已影响0人  篱外听雨

 0

基于onscroll事件实现的loadmore(es6)

FUNC

`loadmore(e) {

  let element = e.target;

  try {

    e.stopPropagation();

  } catch (ex) {

  }

  let clientHeight = element.clientHeight; //可视区域高度

  let scrollTop = element.scrollTop;  //滚动条滚动高度

  let scrollHeight = element.scrollHeight; //滚动内容高度

  if (scrollTop > 0 && (clientHeight + scrollTop) >= scrollHeight) { //如果滚动到底部

    this.getlist('more');

  }

}

`

HTML

<div className="content_all" style={{maxHeight: `${divHeight}px`, height: `${divHeight}px`, overflow: 'auto'}}

              onScroll={this.loadmore}>

</div>

上一篇下一篇

猜你喜欢

热点阅读