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,4 +1,4 @@
import { setStyle, def } from '../utils';
import { setStyle, def, getRect } from '../utils';
export default function resizeMix(art) {
const { $container, $player, $video } = art.template;
@@ -6,7 +6,7 @@ export default function resizeMix(art) {
def(art, 'autoSize', {
value() {
const { videoWidth, videoHeight } = $video;
const { width, height } = $container.getBoundingClientRect();
const { width, height } = getRect($container);
const videoRatio = videoWidth / videoHeight;
const containerRatio = width / height;
if (containerRatio > videoRatio) {
+3 -3
View File
@@ -1,4 +1,4 @@
import { append, setStyle, addClass, removeClass, hasClass, def, isInViewport, createElement } from '../utils';
import { append, setStyle, addClass, removeClass, hasClass, def, isInViewport, createElement, getRect } from '../utils';
export default function miniMix(art) {
const {
@@ -77,7 +77,7 @@ export default function miniMix(art) {
if (isDroging) {
isDroging = false;
removeClass($mini, 'art-mini-droging');
const rect = $mini.getBoundingClientRect();
const rect = getRect($mini);
storage.set('left', rect.left);
storage.set('top', rect.top);
setStyle($mini, 'left', `${rect.left}px`);
@@ -92,7 +92,7 @@ export default function miniMix(art) {
function initMini() {
const { $mini } = art.template;
const rect = $mini.getBoundingClientRect();
const rect = getRect($mini);
const top = window.innerHeight - rect.height - 50;
const left = window.innerWidth - rect.width - 50;
storage.set('top', top);
+2 -2
View File
@@ -1,9 +1,9 @@
import { def } from '../utils';
import { def, getRect } from '../utils';
export default function rectMix(art) {
def(art, 'rect', {
get: () => {
return art.template.$player.getBoundingClientRect();
return getRect(art.template.$player);
},
});