mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(core): add slider dom (#613)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export type { StateAttrMap } from '../../core/ui/types';
|
||||
export { applyElementProps } from './element-props';
|
||||
export { logMissingFeature } from './log';
|
||||
export { getPercentFromPointerEvent } from './pointer';
|
||||
export { applyStateDataAttrs, getStateDataAttrs } from './state-data-attrs';
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { clamp } from '@videojs/utils/number';
|
||||
|
||||
/** Convert a pointer event position to a 0–100 percent along an element's rect. */
|
||||
export function getPercentFromPointerEvent(
|
||||
event: { clientX: number; clientY: number },
|
||||
rect: DOMRect,
|
||||
orientation: 'horizontal' | 'vertical',
|
||||
isRTL: boolean
|
||||
): number {
|
||||
let ratio: number;
|
||||
|
||||
if (orientation === 'vertical') {
|
||||
ratio = 1 - (event.clientY - rect.top) / rect.height;
|
||||
} else if (isRTL) {
|
||||
ratio = (rect.right - event.clientX) / rect.width;
|
||||
} else {
|
||||
ratio = (event.clientX - rect.left) / rect.width;
|
||||
}
|
||||
|
||||
return clamp(ratio * 100, 0, 100);
|
||||
}
|
||||
Reference in New Issue
Block a user