添加自动旋转全屏

This commit is contained in:
Harvey committed 2020-05-15 17:10:05 +08:00
1 parent b08e6a110a
commit cf22fb0535
13 files changed
+186 -108

No files matched your search

@@ -0,0 +1,40 @@
import { addClass, removeClass, hasClass, def, setStyle } from '../utils';
export default function fullscreenRotateMix(art, player) {
const { $container, $player } = art.template;
def(player, 'fullscreenRotate', {
get() {
return hasClass($container, 'art-fullscreen-rotate');
},
set: (value) => {
if (value) {
addClass($container, 'art-fullscreen-rotate');
player.autoSize = true;
const { clientHeight: bodyHeight, clientWidth: bodyWidth } = document.body;
const { clientHeight: playerHeight, clientWidth: playerWidth } = $player;
const bodyRatio = bodyWidth / bodyHeight;
const videoRatio = playerWidth / playerHeight;
const needSpin = bodyRatio < videoRatio;
if (needSpin) {
const scale = Math.min(bodyHeight / playerWidth, bodyWidth / playerHeight).toFixed(2);
setStyle($player, 'transform', `rotate(90deg) scale(${scale},${scale})`);
art.emit('fullscreenRotateChange', true);
}
} else {
removeClass($container, 'art-fullscreen-rotate');
player.autoSize = art.option.autoSize;
setStyle($player, 'transform', null);
art.emit('fullscreenRotateChange', false);
}
},
});
def(player, 'fullscreenRotateToggle', {
set(value) {
if (value) {
player.fullscreenRotate = !player.fullscreenRotate;
}
},
});
}