在一秒之内点击多次, 只触发一次事件, 比如避免多次点击登录按钮, 重复发请求; undersore 也有 _debounce这个函数.
var a = document.getElementById('a');
a.addEventListener('click', bound(function(){
console.log(2)
},1000))
function bound(fn, time){
var st = null;
return function(){
if(!st){
fn();
st = new Date();
}
if(new Date - st >= time){
fn();
st = new Date();
}
else{
//不到时间不执行
}
}
}
页面是否到了底部
https://www.cnblogs.com/koleyang/p/4939853.html
document.documentElement.scrollTop 滚动后, 上面被隐藏页面的高度
document.documentElement.clientHeight 页面的可见部分
document.documentElement.scrollHeight 页面所有元素高的总和
往下拉的时候, 通常 隐藏高度 + 可见高度 和 总和 是相等的;
但手机再往下拉 会出现空白 这时候 说明见底了, 会出现 大于元素总和的情况
define(['zepto'], function(zepto){
var Events = {
scrollBottom: function(call,win,doc){
var win = win || window;
var doc = doc || document;
var scrollTop, scrollHeight, clientHeight;
var dd = doc.documentElement, db = doc.body;
$(win).on('scroll',function () {
scrollTop = dd.scrollTop || db.scrollTop;
clientHeight = dd.clientHeight;
scrollHeight = dd.scrollHeight;
if (scrollTop + clientHeight >= scrollHeight) {
//console.log( scrollTop + ' ' + clientHeight );
//console.log(scrollHeight);
//console.log( '----------------------------' );
call();
$("#footerForApp").unbind();
$("#footerForApp").on("touchmove", function (e) {
// body...
e.preventDefault();
})
}
$("#footerForApp").unbind();
$("#footerForApp").on("touchmove", function (e) {
// body...
e.preventDefault();
})
});
},
unbindScroll: function(win){
var win = win || window;
$(win).off();
}
}
return {
scrollBottom: Events.scrollBottom,
unbindScroll: Events.unbindScroll
};
});
浙公网安备 33010602011771号