Use Prettier for ESLint formatting TypeScript (#23631)
This commit is contained in:
parent
6aeb162927
commit
51b83ed195
31 changed files with 407 additions and 245 deletions
|
@ -1,13 +1,23 @@
|
|||
const easingOutQuint = (x: number, t: number, b: number, c: number, d: number) => c * ((t = t / d - 1) * t * t * t * t + 1) + b;
|
||||
const scroll = (node: Element, key: 'scrollTop' | 'scrollLeft', target: number) => {
|
||||
const easingOutQuint = (
|
||||
x: number,
|
||||
t: number,
|
||||
b: number,
|
||||
c: number,
|
||||
d: number
|
||||
) => c * ((t = t / d - 1) * t * t * t * t + 1) + b;
|
||||
const scroll = (
|
||||
node: Element,
|
||||
key: 'scrollTop' | 'scrollLeft',
|
||||
target: number
|
||||
) => {
|
||||
const startTime = Date.now();
|
||||
const offset = node[key];
|
||||
const gap = target - offset;
|
||||
const duration = 1000;
|
||||
let interrupt = false;
|
||||
const offset = node[key];
|
||||
const gap = target - offset;
|
||||
const duration = 1000;
|
||||
let interrupt = false;
|
||||
|
||||
const step = () => {
|
||||
const elapsed = Date.now() - startTime;
|
||||
const elapsed = Date.now() - startTime;
|
||||
const percentage = elapsed / duration;
|
||||
|
||||
if (percentage > 1 || interrupt) {
|
||||
|
@ -25,7 +35,14 @@ const scroll = (node: Element, key: 'scrollTop' | 'scrollLeft', target: number)
|
|||
};
|
||||
};
|
||||
|
||||
const isScrollBehaviorSupported = 'scrollBehavior' in document.documentElement.style;
|
||||
const isScrollBehaviorSupported =
|
||||
'scrollBehavior' in document.documentElement.style;
|
||||
|
||||
export const scrollRight = (node: Element, position: number) => isScrollBehaviorSupported ? node.scrollTo({ left: position, behavior: 'smooth' }) : scroll(node, 'scrollLeft', position);
|
||||
export const scrollTop = (node: Element) => isScrollBehaviorSupported ? node.scrollTo({ top: 0, behavior: 'smooth' }) : scroll(node, 'scrollTop', 0);
|
||||
export const scrollRight = (node: Element, position: number) =>
|
||||
isScrollBehaviorSupported
|
||||
? node.scrollTo({ left: position, behavior: 'smooth' })
|
||||
: scroll(node, 'scrollLeft', position);
|
||||
export const scrollTop = (node: Element) =>
|
||||
isScrollBehaviorSupported
|
||||
? node.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
: scroll(node, 'scrollTop', 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue