- var zdMlCoo = {
- throttle: function (fn, delay, mustRunDelay) {
- /*函数节流,适用于,需不停执行的函数*/
- var timer = null;
- var t_start;
- return function () {
- var context = this, args = arguments, t_curr = +new Date();
- clearTimeout(timer);
- if (!t_start) {
- t_start = t_curr;
- }
- if (t_curr - t_start >= mustRunDelay) {
- fn.apply(context, args);
- t_start = t_curr;
- }
- else {
- timer = setTimeout(function () {
- fn.apply(context, args);
- }, delay);
- }
- };
- }
- };
- //该片段来自于http://www.codesnippet.cn/detail/0707201614808.html
来源: http://www.codesnippet.cn/detail/0707201614808.html