本文整理汇总了TypeScript中lodash-es/clamp.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: scrollTo
export function scrollTo(
scrollbar: I.Scrollbar,
x: number,
y: number,
duration = 0,
{ easing = defaultEasing, callback = null }: Partial<I.ScrollToOptions> = {},
) {
const {
options,
offset,
limit,
} = scrollbar;
if (options.renderByPixels) {
// ensure resolved with integer
x = Math.round(x);
y = Math.round(y);
}
const startX = offset.x;
const startY = offset.y;
const disX = clamp(x, 0, limit.x) - startX;
const disY = clamp(y, 0, limit.y) - startY;
const start = Date.now();
function scroll() {
const elapse = Date.now() - start;
const progress = duration ? easing(Math.min(elapse / duration, 1)) : 1;
scrollbar.setPosition(
startX + disX * progress,
startY + disY * progress,
);
if (elapse >= duration) {
if (typeof callback === 'function') {
callback.call(scrollbar);
}
} else {
const animationID = requestAnimationFrame(scroll);
animationIDStorage.set(scrollbar, animationID);
}
}
cancelAnimationFrame(animationIDStorage.get(scrollbar) as number);
scroll();
}
示例2: addEvent
addEvent(container, 'click', (evt: MouseEvent) => {
if (isMouseMoving || !isOneOf(evt.target, [xAxis.element, yAxis.element])) {
return;
}
const track = evt.target as HTMLElement;
const direction = getTrackDirection(track);
const rect = track.getBoundingClientRect();
const clickPos = getPosition(evt);
const { offset, limit } = scrollbar;
if (direction === Direction.X) {
const offsetOnTrack = clickPos.x - rect.left - xAxis.thumb.displaySize / 2;
scrollbar.setMomentum(
clamp(calcOffset(direction, offsetOnTrack) - offset.x, -offset.x, limit.x - offset.x),
0,
);
}
if (direction === Direction.Y) {
const offsetOnTrack = clickPos.y - rect.top - yAxis.thumb.displaySize / 2;
scrollbar.setMomentum(
0,
clamp(calcOffset(direction, offsetOnTrack) - offset.y, -offset.y, limit.y - offset.y),
);
}
});
示例3: scroll
function scroll({ x, y }) {
if (!x && !y) return;
// DISALLOW delta transformation
scrollbar.setMomentum(
clamp(offset.x + x, 0, limit.x) - offset.x,
clamp(offset.y + y, 0, limit.y) - offset.y,
);
animationID = requestAnimationFrame(() => {
scroll({ x, y });
});
}
示例4: scrollIntoView
export function scrollIntoView(
scrollbar: I.Scrollbar,
elem: HTMLElement,
{
alignToTop = true,
onlyScrollIfNeeded = false,
offsetTop = 0,
offsetLeft = 0,
offsetBottom = 0,
}: Partial<I.ScrollIntoViewOptions> = {},
) {
const {
containerEl,
bounding,
offset,
limit,
} = scrollbar;
if (!elem || !containerEl.contains(elem)) return;
const targetBounding = elem.getBoundingClientRect();
if (onlyScrollIfNeeded && scrollbar.isVisible(elem)) return;
const delta = alignToTop ? targetBounding.top - bounding.top - offsetTop : targetBounding.bottom - bounding.bottom + offsetBottom;
scrollbar.setMomentum(
targetBounding.left - bounding.left - offsetLeft,
clamp(delta, -offset.y, limit.y - offset.y),
);
}
示例5: setPosition
export function setPosition(
scrollbar: I.Scrollbar,
x: number,
y: number,
): I.ScrollStatus | null {
const {
options,
offset,
limit,
track,
contentEl,
} = scrollbar;
if (options.renderByPixels) {
x = Math.round(x);
y = Math.round(y);
}
x = clamp(x, 0, limit.x);
y = clamp(y, 0, limit.y);
// position changed -> show track for 300ms
if (x !== offset.x) track.xAxis.show();
if (y !== offset.y) track.yAxis.show();
if (!options.alwaysShowTracks) {
track.autoHideOnIdle();
}
if (x === offset.x && y === offset.y) {
return null;
}
offset.x = x;
offset.y = y;
setStyle(contentEl, {
'-transform': `translate3d(${-x}px, ${-y}px, 0)`,
});
track.update();
return {
offset: { ...offset },
limit: { ...limit },
};
}
示例6: return
return (proto: any, key: string) => {
const alias = `_${key}`;
Object.defineProperty(proto, key, {
get() {
return this[alias];
},
set(val: number) {
Object.defineProperty(this, alias, {
value: clamp(val, min, max),
enumerable: false,
writable: true,
configurable: true,
});
},
enumerable: true,
configurable: true,
});
};