1 Star 0 Fork 0

波吉/sUtils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
throttle.js 550 Bytes
一键复制 编辑 原始数据 按行查看 历史
jokerls 提交于 2022-01-11 15:18 +08:00 . 迁移到gitee
/**
* @description 节流
* @param {Function} fn 业务函数
* @param {Number} delay 节流延时,单位:毫秒
*/
function throttle(fn, delay = 100) {
let timer = null
return function() {
if (timer) {
return
}
timer = setTimeout(() => {
fn.apply(this, arguments)
timer = null
}, delay)
}
}
/**
* 使用示例
*/
// <div id="dragDiv" draggable="true">
// 可拖拽
// </div>
const div = document.getElementById('dragDiv')
div.addEventListener('drag', throttle((e) => {
console.log(e.offsetX, e.offsetY);
}, 150))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Jokerlsss/s-utils.git
[email protected]:Jokerlsss/s-utils.git
Jokerlsss
s-utils
sUtils
master

搜索帮助