掘友等级
获得徽章 0
#每天一个知识点#
js 实现防抖和节流函数
1. 防抖函数(Debounce)
function debounce(func, delay) {
let timer;
return function(...args) {
const context = this;
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(context, args);
}, delay);
};
}
// 使用示例
window.addEventListener('resize', debounce(() => {
console.log('Window resized');
}, 500));
2. 节流函数(Throttle)
function throttle(func, interval) {
let lastTime = 0;
return function(...args) {
const now = Date.now();
if (now - lastTime >= interval) {
func.apply(this, args);
lastTime = now;
}
};
}
// 使用示例
window.addEventListener('scroll', throttle(() => {
console.log('Window scrolled');
}, 500));
国外汽车品牌用人名,是一种普遍现象,中国呢,好像只有魏八一吧,就冲这个就值得表达一下尊重
大家用bun install的时候是不是老经常卡在某个包不动,我装了一上午都没装好, 梯子WIFI热点都试过了
不加班要扣绩效,开会投影电视不关也要扣绩效
jym 出息了 我周末尽然敢去看奔驰了 看了c和GLB,我尽然觉得奔驰C空间小 内饰丑 大屏界面也丑 感觉像上一代的产品 ~ 可能被新能源给洗了眼 ~
下一页