mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 13:51:20 -08:00
添加自动尺寸
This commit is contained in:
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user