h5-cli
Version:
hello
68 lines (57 loc) • 1.73 kB
JavaScript
"use strict";
/**
\u4f9d\u8d56zepto.js
\u6eda\u52a8\u52a0\u8f7d\u7ec4\u4ef6
*/
define("component/ScrollHooker", function (require, exports, module) {
var CouponHooker = function CouponHooker(t) {
this.prevHeight = 0;
//\u662f\u5426\u5728\u6fc0\u6d3b\u72b6\u6001
this.activation = 1;
//\u5bb9\u5668
this.container = t || document.body;
this.scrollElement = this.container == document.body ? window : this.container;
//\u9884\u52a0\u8f7d\u5927\u5c0f
this.bufferHeight = 360, this.init();
};
CouponHooker.prototype = {
init: function init() {
var t = this;
//\u76d1\u542cscroll\u4e8b\u4ef6
$(this.scrollElement).on("scroll", function () {
t.scroll();
});
},
scroll: function scroll() {
var container = this.container;
var innerHeight = container == document.body ? window.innerHeight : container.clientHeight;
var scrollHeight = container.scrollHeight;
var scrollTop = container.scrollTop;
//\u7a97\u53e3\u9ad8\u5ea6\u53d1\u751f\u53d8\u5316\uff0c\u81ea\u52a8\u6fc0\u6d3b
if (scrollHeight != this.prevHeight) {
this.start();
}
//\u89e6\u53d1onEnd\u4e8b\u4ef6
// console.log(1 == this.activation ,!this.isRecovery, scrollHeight - scrollTop - innerHeight - this.bufferHeight < 0);
if (1 != this.activation || this.isRecovery) {
return;
}
if (scrollHeight - scrollTop - innerHeight - this.bufferHeight < 0) {
this.stop();
this.prevHeight = scrollHeight;
this.onEnd();
}
},
stop: function stop() {
this.activation = 0;
},
start: function start() {
this.activation = 1;
},
recovery: function recovery() {
this.isRecovery = 1;
},
onEnd: function onEnd() {}
};
module.exports = CouponHooker;
});