格式化

This commit is contained in:
Harvey Zack committed 2018-11-21 19:45:44 +08:00
1 parent 0454f785be
commit 203ad0d3a0
75 files changed
+3120 -2904

No files matched your search

+33 -31
View File
@@ -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');
},
});
}