mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-09-04 15:09:45 +08:00
chore: rename scroller param
This commit is contained in:
parent
0993b394b1
commit
cab097fafb
@ -3,15 +3,19 @@ import { getScrollTop, setScrollTop } from '../utils/dom/scroll';
|
|||||||
|
|
||||||
let scrollLeftRafId: number;
|
let scrollLeftRafId: number;
|
||||||
|
|
||||||
export function scrollLeftTo(el: HTMLElement, to: number, duration: number) {
|
export function scrollLeftTo(
|
||||||
|
scroller: HTMLElement,
|
||||||
|
to: number,
|
||||||
|
duration: number
|
||||||
|
) {
|
||||||
cancelRaf(scrollLeftRafId);
|
cancelRaf(scrollLeftRafId);
|
||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const from = el.scrollLeft;
|
const from = scroller.scrollLeft;
|
||||||
const frames = duration === 0 ? 1 : Math.round((duration * 1000) / 16);
|
const frames = duration === 0 ? 1 : Math.round((duration * 1000) / 16);
|
||||||
|
|
||||||
function animate() {
|
function animate() {
|
||||||
el.scrollLeft += (to - from) / frames;
|
scroller.scrollLeft += (to - from) / frames;
|
||||||
|
|
||||||
if (++count < frames) {
|
if (++count < frames) {
|
||||||
scrollLeftRafId = raf(animate);
|
scrollLeftRafId = raf(animate);
|
||||||
@ -22,12 +26,12 @@ export function scrollLeftTo(el: HTMLElement, to: number, duration: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function scrollTopTo(
|
export function scrollTopTo(
|
||||||
el: HTMLElement,
|
scroller: HTMLElement,
|
||||||
to: number,
|
to: number,
|
||||||
duration: number,
|
duration: number,
|
||||||
callback: Function
|
callback: Function
|
||||||
) {
|
) {
|
||||||
let current = getScrollTop(el);
|
let current = getScrollTop(scroller);
|
||||||
|
|
||||||
const isDown = current < to;
|
const isDown = current < to;
|
||||||
const frames = duration === 0 ? 1 : Math.round((duration * 1000) / 16);
|
const frames = duration === 0 ? 1 : Math.round((duration * 1000) / 16);
|
||||||
@ -40,7 +44,7 @@ export function scrollTopTo(
|
|||||||
current = to;
|
current = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
setScrollTop(el, current);
|
setScrollTop(scroller, current);
|
||||||
|
|
||||||
if ((isDown && current < to) || (!isDown && current > to)) {
|
if ((isDown && current < to) || (!isDown && current > to)) {
|
||||||
raf(animate);
|
raf(animate);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user