本文整理匯總了TypeScript中ux/dom.getScroll函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getScroll函數的具體用法?TypeScript getScroll怎麽用?TypeScript getScroll使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getScroll函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getScroll
const step = () => {
const current = getScroll(elem);
if (current.x === last.x && current.y === last.y) {
if (Math.abs(leftX) > Math.abs(deltaX)) {
current.x += deltaX;
leftX -= deltaX;
} else {
current.x = value.x!;
}
if (Math.abs(leftY) > Math.abs(deltaY)) {
current.y += deltaY;
leftY -= deltaY;
} else {
current.y = value.y!;
}
setScroll(elem, current);
last = getScroll(elem);
setTimeout(step, 10);
} else {
callback && callback(last);
}
};
示例2: scrollIntoViewIfNeeded
export function scrollIntoViewIfNeeded(elem: HTMLElement | Document, scrollable: HTMLElement | Document = scrollParent(elem), duration?: number, padding = 0, offset = 0, callback?: (value: Point) => void) {
const container = getRect(scrollable);
const rect = getRect(elem);
const deltaY = rect.y - container.y;
const deltaX = rect.x - container.x;
const value = getScroll(scrollable);
if (deltaY < padding) {
value.y += deltaY - offset;
} else if (deltaY + rect.height + padding > container.height) {
value.y += deltaY - container.height + rect.height + offset;
} else {
delete value.y;
}
if (deltaX < padding) {
value.x += deltaX - offset;
} else if (deltaX + rect.width + padding > container.width) {
value.x += deltaX - container.width + rect.width + offset;
} else {
delete value.x;
}
scrollTo(scrollable, value, duration, callback);
}
示例3: scrollTo
export function scrollTo(elem: HTMLElement | Document, value: Partial<Point>, duration = 150, callback?: (value: Point) => void) {
let last = getScroll(elem);
if (duration === 0) {
setScroll(elem, value);
} else if (value.x != null || value.y != null) {
let leftX = (value.x! - last.x) || 0;
let leftY = (value.y! - last.y) || 0;
const count = duration / 10;
const deltaX = leftX / count;
const deltaY = leftY / count;
const step = () => {
const current = getScroll(elem);
if (current.x === last.x && current.y === last.y) {
if (Math.abs(leftX) > Math.abs(deltaX)) {
current.x += deltaX;
leftX -= deltaX;
} else {
current.x = value.x!;
}
if (Math.abs(leftY) > Math.abs(deltaY)) {
current.y += deltaY;
leftY -= deltaY;
} else {
current.y = value.y!;
}
setScroll(elem, current);
last = getScroll(elem);
setTimeout(step, 10);
} else {
callback && callback(last);
}
};
step();
return;
}
callback && callback(last);
}
示例4: scrollIntoView
export function scrollIntoView(elem: HTMLElement | Document, position?: ScrollLogicalPosition, scrollable: HTMLElement | Document = scrollParent(elem), duration?: number, offset = 0, callback?: (value: Point) => void) {
const container = getRect(scrollable);
const rect = getRect(elem);
const deltaY = rect.y - container.y;
const deltaX = rect.x - container.x;
const value = getScroll(scrollable);
if (!position || position === "start" || position === "nearest" && deltaY <= (container.height - rect.height) / 2) {
value.y += deltaY - offset;
} else {
value.y += deltaY - container.height + rect.height + offset;
if (position === "center") {
value.y += (container.height - rect.height) / 2;
}
}
if (!position || position === "start" || position === "nearest" && deltaX <= (container.width - rect.width) / 2) {
value.x -= -deltaX + offset;
} else {
value.x -= -deltaX + container.width - rect.width - offset;
if (position === "center") {
value.x += (container.width - rect.width) / 2;
}
}
scrollTo(scrollable, value, duration, callback);
}
示例5: scrollBy
export function scrollBy(elem: HTMLElement | Document, value: Partial<Point>, duration?: number, callback?: (value: Point) => void) {
const scroll = getScroll(elem);
if (value.x != null) scroll.x += value.x;
if (value.y != null) scroll.y += value.y;
scrollTo(elem, scroll, duration, callback);
}