mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-22 13:21:20 -08:00
add autoOrientation
This commit is contained in:
1 parent
4539a46a82
commit
b292b769bd
5 files changed
+82
-5
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { setStyle } from '../utils';
|
||||
|
||||
export default function autoOrientation(art) {
|
||||
const {
|
||||
option,
|
||||
template: { $player, $video },
|
||||
} = art;
|
||||
|
||||
art.on('fullscreenWeb', (state) => {
|
||||
if (state) {
|
||||
const { videoWidth, videoHeight } = $video;
|
||||
const { clientWidth: viewWidth, clientHeight: viewHeight } = document.documentElement;
|
||||
if (
|
||||
(videoWidth > videoHeight && viewWidth < viewHeight) ||
|
||||
(videoWidth < videoHeight && viewWidth > viewHeight)
|
||||
) {
|
||||
setStyle($player, 'width', `${viewHeight}px`);
|
||||
setStyle($player, 'height', `${viewWidth}px`);
|
||||
setStyle($player, 'transform', `rotate(90deg) translate(0,-${viewWidth}px)`);
|
||||
setStyle($player, 'transform-origin', '0 0');
|
||||
}
|
||||
} else {
|
||||
setStyle($player, 'width', null);
|
||||
setStyle($player, 'height', null);
|
||||
setStyle($player, 'transform', null);
|
||||
setStyle($player, 'transform-origin', null);
|
||||
art.autoSize = option.autoSize;
|
||||
art.notice.show = '';
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
name: 'autoOrientation',
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { errorHandle, isMobile, has, def } from '../utils';
|
||||
import miniProgressBar from './miniProgressBar';
|
||||
import autoOrientation from './autoOrientation';
|
||||
import autoPlayback from './autoPlayback';
|
||||
import lock from './lock';
|
||||
|
||||
@@ -22,6 +23,10 @@ export default class Plugins {
|
||||
this.add(autoPlayback);
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
this.add(autoOrientation);
|
||||
}
|
||||
|
||||
for (let index = 0; index < option.plugins.length; index++) {
|
||||
this.add(option.plugins[index]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user