mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-19 19:51:20 -08:00
try screen.orientation.lock
This commit is contained in:
1 parent
e4f815e24f
commit
cf5099f259
3 files changed
+200
-187
No files matched your search
@@ -38,6 +38,29 @@ export default function autoOrientation(art) {
|
||||
}
|
||||
});
|
||||
|
||||
art.on('fullscreen', (state) => {
|
||||
const lastOrientation = screen.orientation.type;
|
||||
if (state) {
|
||||
const { videoWidth, videoHeight } = $video;
|
||||
const { clientWidth: viewWidth, clientHeight: viewHeight } = document.documentElement;
|
||||
if (
|
||||
(videoWidth > videoHeight && viewWidth < viewHeight) ||
|
||||
(videoWidth < videoHeight && viewWidth > viewHeight)
|
||||
) {
|
||||
const oppositeOrientation = lastOrientation.startsWith('portrait') ? 'landscape' : 'portrait';
|
||||
screen.orientation.lock(oppositeOrientation).then(() => {
|
||||
addClass($player, 'art-auto-orientation-fullscreen');
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (hasClass($player, 'art-auto-orientation-fullscreen')) {
|
||||
screen.orientation.lock(lastOrientation).then(() => {
|
||||
removeClass($player, 'art-auto-orientation-fullscreen');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
name: 'autoOrientation',
|
||||
get state() {
|
||||
|
||||
Reference in new issue
Block a user