gravediggin但如果你需要检查它的js 油门或防抖动功能
用法:
//resize events gets processed 500ms after the last Event
addEventListener("resize", _debounce(function(){ foo;}, 500));
//resize events get processed every 500ms
addEventListener("resize", _throttle(function(){ foo;}, 500));
代码:
/*waits 'delay' time after the last event to fire */
_debounce = function(fn, delay) {
var timer = null;
return function() {
var context = this,
args = arguments;
clearTimeout(timer);
timer = setTimeout(function() {
fn.apply(context, args);
}, delay);
};
};
/* triggers every 'treshhold' ms, */
_throttle = function(fn, threshhold, scope) {
threshhold = threshhold || 250;
var last,
deferTimer;
return function() {
var context = scope || this;
var now = +new Date(),
args = arguments;
if (last && now < last + threshhold) {
// hold on to it
clearTimeout(deferTimer);
deferTimer = setTimeout(function() {
last = now;
fn.apply(context, args);
}, threshhold);
} else {
last = now;
fn.apply(context, args);
}
};
};
你是什么acutal代码? – 2011-03-02 12:04:56
由于HTML规范中的模糊性,这是由WebKit和IE执行的错误。从那以后,这个规范已经被澄清,直到旋钮被释放后,'变化'事件才会开始。要在用户滑动旋钮时获取值,应该使用“输入”事件。但是,WebKit和IE还没有解决这个实现bug。 HTML规格修订版本:http://html5.org/tools/web-apps-tracker?from=7786&to=7787 – JeremiahLee 2013-09-11 21:57:49