Skip to content

Commit

Permalink
fix: solve the smooth scrolling scene, the y value obtained is the da…
Browse files Browse the repository at this point in the history
…ta 100ms ago
  • Loading branch information
xujiujiu committed Apr 7, 2024
1 parent 39f3e4d commit 67c8d38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 1 addition & 4 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,7 @@ export function initScrollObserver({
});
}
}),
sampling.scroll || 100,
{
trailing: true
}
sampling.scroll || 100
),
);
return on('scroll', updatePosition, doc);
Expand Down
13 changes: 11 additions & 2 deletions packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,19 @@ export function throttle<T>(
previous = now;
func.apply(context, args);
} else if (!timeout && options.trailing !== false) {
const argumentsList = args.map((arg: Omit<T, 'target'>) => {
return {
...arg,
target: arg.target || null
}
})
timeout = setTimeout(() => {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
func.apply(context, args);
if (timeout) {
clearTimeout(timeout)
timeout = null;
}
func.apply(context, argumentsList);
}, remaining);
}
};
Expand Down

0 comments on commit 67c8d38

Please sign in to comment.