react獲取到鼠標滾動的高度

如果是特定id的dom對象的話,使用的是react的ref方法。

//搜索列表鼠標滾動事件

handleScroll(e){
    let clientHeight = this.refs.bodyBox.clientHeight; //可視區域高度
    let scrollTop  = this.refs.bodyBox.scrollTop;  //滾動條滾動高度
    let scrollHeight = this.refs.bodyBox.scrollHeight; //滾動內容高度
    if((clientHeight+scrollTop)==(scrollHeight)){ //如果滾動到底部 }  
}
在render
<div className="contentBox" onScroll={this.handleScroll}  ref="bodyBox">

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章