函数节流和防抖动
来源:互联网 发布:ttrgb风扇软件控制 编辑:程序博客网 时间:2024/04/30 08:40
<!doctype html><html> <head> <meta charset="utf-8"> <title>赤壁之战</title> <meta http-equiv="X-UA-Compatible" content="edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="Keywords" content="赤壁之战"> <meta name="description" content="赤壁之战"> </head><body><script>function throttle(func,wait,mustRun){ var timeout = null; var startTime = new Date(); return function (){ var context = this, args = arguments, curTime = new Date(); clearTimeout(timeout); if(curTime - startTime >= mustRun){ func.apply(context,args); startTime = curTime; }else{ timeout = setTimeout(func,wait); } }}function fn(){ console.log(1);}function fn2(){ console.log(2);}window.addEventListener('scroll',fn,false); window.addEventListener('scroll',throttle(fn2,500,1000),false);</script></body></html>
<!doctype html><html> <head> <meta charset="utf-8"> <title>赤壁之战</title> <meta http-equiv="X-UA-Compatible" content="edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="Keywords" content="赤壁之战"> <meta name="description" content="赤壁之战"> </head><body><script>function debounce(fn,wait){ var timeout = null; return function (){ clearTimeout(timeout); timeout = setTimeout(fn,wait); }}function debounce2 (fn,wait,immeditate){ var timeout = null; return function (){ var context = this, args = arguments; var later = function (){ timeout = null; if(!immeditate) fn.apply(context,args); } var callNow = immeditate & !timeout; clearTimeout(timeout); timeout = setTimeout(later,wait); if(callNow) func.apply(context,args) }}function fn(){ console.log(1);}function fn2(){ console.log(2);}window.addEventListener('scroll',fn,false); window.addEventListener('scroll',debounce2(fn2,500),false);</script> </body></html>
0 0
- 函数节流和防抖动
- 函数防抖和节流
- js:防抖动与节流
- js函数节流和去抖动
- 函数防抖和函数节流
- 节流和防抖
- 防抖函数和节流函数小列
- 函数节流 + 函数防抖
- JavaScript小知识点(二):函数防抖和节流
- 函数节流与防抖
- 函数防抖与节流
- 函数的节流 & 防抖
- JS函数节流防抖
- 函数节流与防抖
- [JS]防抖和节流
- [JS]防抖和节流
- js函数防抖与函数节流
- 函数防抖与函数节流
- 关于sdk更新后报错
- Bourne Shell编程杂记
- QT 下TCP客户端
- C/C++中volatile关键字详解
- bzoj4569: [Scoi2016]萌萌哒
- 函数节流和防抖动
- 安卓日记——设计简洁好看的UI
- 微信JS SDK Demo
- 几何画板中如何将坐标轴刻度数字变大
- view 的 clipsToBounds属性
- JSON 字符串 与 java 对象的转换
- halcon中的数据类型与语法结构
- Oracle RAC的机制与测试方法
- 比特率 波特率 数据传输速率 区别