添加自动尺寸

This commit is contained in:
Harvey Zack committed 2018-11-09 14:36:48 +08:00
1 parent 1d40d1c46b
commit 7d766ac1d5
23 files changed
+154 -54

No files matched your search

@@ -0,0 +1,32 @@
import { setStyle } from '../utils';
export default function resizeMix(art, player) {
const { refs: { $container, $player, $video } } = art;
Object.defineProperty(player, 'autoSize', {
value: () => {
const { videoWidth, videoHeight } = $video;
const { width, height } = $container.getBoundingClientRect();
const videoRatio = videoWidth / videoHeight;
const containerRatio = width / height;
$container.classList.add('artplayer-auto-size');
if (containerRatio > videoRatio) {
const percentage = height * videoRatio / width * 100;
setStyle($player, 'width', `${percentage}%`);
setStyle($player, 'height', '100%');
} else {
const percentage = width / videoRatio / height * 100;
setStyle($player, 'width', '100%');
setStyle($player, 'height', `${percentage}%`);
}
}
});
Object.defineProperty(player, 'autoSizeRemove', {
value: () => {
$container.classList.remove('artplayer-auto-size');
setStyle($player, 'width', null);
setStyle($player, 'height', null);
}
});
}