Files
v10/dist/dev/dom/utils/pointer.js
T

15 lines
628 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { clamp } from "@videojs/utils/number";
//#region src/dom/utils/pointer.ts
/** Convert a pointer event position to a 0100 percent along an element's rect. */
function getPercentFromPointerEvent(event, rect, orientation, isRTL) {
let ratio;
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;
if (!Number.isFinite(ratio)) return 0;
return clamp(ratio * 100, 0, 100);
}
//#endregion
export { getPercentFromPointerEvent };
//# sourceMappingURL=pointer.js.map