feat: Add getRect function to utils and update player and control modules to use it

This commit is contained in:
Harvey Zack committed 2024-06-08 12:17:45 +08:00
1 parent 2721f61b41
commit 232b8a3e17
10 files changed
+36 -27

No files matched your search

+2 -2
View File
@@ -1,8 +1,8 @@
import { query, clamp, append, setStyle, secondToTime, includeFromEvent, isMobile } from '../utils';
import { query, clamp, append, setStyle, secondToTime, includeFromEvent, isMobile, getRect } from '../utils';
export function getPosFromEvent(art, event) {
const { $progress } = art.template;
const { left } = $progress.getBoundingClientRect();
const { left } = getRect($progress);
const eventLeft = isMobile ? event.touches[0].clientX : event.clientX;
const width = clamp(eventLeft - left, 0, $progress.clientWidth);
const second = (width / $progress.clientWidth) * art.duration;
+2 -2
View File
@@ -1,4 +1,4 @@
import { append, setStyle, isMobile } from '../utils';
import { append, setStyle, isMobile, getRect } from '../utils';
export default function volume(option) {
return (art) => ({
@@ -17,7 +17,7 @@ export default function volume(option) {
const $indicator = append($slider, `<div class="art-volume-indicator"></div>`);
function getVolumeFromEvent(event) {
const { top, height } = $slider.getBoundingClientRect();
const { top, height } = getRect($slider);
return 1 - (event.clientY - top) / height;
}