mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 08:01:20 -08:00
格式化
This commit is contained in:
1 parent
0454f785be
commit
203ad0d3a0
75 files changed
+3120
-2904
No files matched your search
@@ -1,38 +1,40 @@
|
||||
import { setStyle } from '../utils';
|
||||
|
||||
export default function resizeMix(art, player) {
|
||||
const { refs: { $container, $player, $video } } = art;
|
||||
const {
|
||||
refs: { $container, $player, $video },
|
||||
} = art;
|
||||
|
||||
Object.defineProperty(player, 'autoSizeState', {
|
||||
get: () => $container.classList.contains('artplayer-auto-size')
|
||||
});
|
||||
Object.defineProperty(player, 'autoSizeState', {
|
||||
get: () => $container.classList.contains('artplayer-auto-size'),
|
||||
});
|
||||
|
||||
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}%`);
|
||||
}
|
||||
art.emit('autoSizeChange');
|
||||
}
|
||||
});
|
||||
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}%`);
|
||||
}
|
||||
art.emit('autoSizeChange');
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(player, 'autoSizeRemove', {
|
||||
value: () => {
|
||||
$container.classList.remove('artplayer-auto-size');
|
||||
setStyle($player, 'width', null);
|
||||
setStyle($player, 'height', null);
|
||||
art.emit('autoSizeRemove');
|
||||
}
|
||||
});
|
||||
Object.defineProperty(player, 'autoSizeRemove', {
|
||||
value: () => {
|
||||
$container.classList.remove('artplayer-auto-size');
|
||||
setStyle($player, 'width', null);
|
||||
setStyle($player, 'height', null);
|
||||
art.emit('autoSizeRemove');
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user