mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 23:51:20 -08:00
feat: Add getRect function to utils and update player and control modules to use it
This commit is contained in:
1 parent
2721f61b41
commit
232b8a3e17
10 files changed
+36
-27
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user