123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- class ScrollEventPlugin {
- constructor() {
- this.eventLock = false;
- this.widget = null;
- this.dom = null;
- this.onToBottomCallback = null;
- this.onToTopCallback = null;
- }
- bind(widget){
- this.widget = widget;
- this.dom = widget.con;
- this.widget.on('scrollend', ()=>{
- if(this.eventLock) { return; }
- let wTop = this.dom.getElementsByClassName('scroll-list')[0].style.top;
- wTop = parseFloat(wTop.replace('px' , ''));
- let scrollHeight = this.dom.clientHeight;
- let listHeight = this.dom.getElementsByClassName('scroll-list')[0].clientHeight;
- let maxOffset = listHeight - scrollHeight;
- if(wTop == 0 && this.onToTopCallback){
- this.onToTopCallback();
- this.eventLock = true;
- return;
- }
- if(wTop == maxOffset * -1 && this.onToBottomCallback){
- this.onToBottomCallback();
- this.eventLock = true;
- }
- });
- }
- onScrollToBottom(callback){
- this.onToBottomCallback = callback;
- }
- onScrollToTop(callback){
- this.onToTopCallback = callback;
- }
- releaseEventLock(){
- this.eventLock = false;
- }
- }
- module.exports = ScrollEventPlugin;
|