滚动加载方法
/**
*
* @param {*} scrollClass
* @param {*} fn
* @param {*} preventLoad
* 滚动的元素id
* 滚动回调方法
* 锁死滚动的方法
*/
var initScroll = function(scrollClass,fn){ var self = this; var beforeScrollTop = document.body.scrollTop || document.documentElement.scrollTop; document.getElementById(scrollClass).addEventListener('scroll', function(e){ var afterScrollTop = this.scrollTop || this.scrollTop, windowHeight = window.innerHeight, scrollHeight = this.scrollHeight, delta = afterScrollTop - beforeScrollTop; if( (afterScrollTop + windowHeight)/scrollHeight>=0.95 ){ (typeof fn=='function') && fn(); } //将新的滑动距离赋值给上一次的滑动 beforeScrollTop = afterScrollTop; }) }