mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 20:21:20 -08:00
优化画面调整
This commit is contained in:
1 parent
5cbb8bd1f3
commit
7e4420d841
5 files changed
+119
-119
No files matched your search
@@ -12,45 +12,36 @@ export default function aspectRatioMix(art, player) {
|
||||
return $player.dataset.aspectRatio || '';
|
||||
},
|
||||
set(ratio) {
|
||||
if (ratio) {
|
||||
const ratioList = ['default', '4:3', '16:9'];
|
||||
errorHandle(
|
||||
ratioList.includes(ratio),
|
||||
`'aspectRatio' only accept ${ratioList.toString()} as parameters`,
|
||||
);
|
||||
const ratioList = [false, 'default', '4:3', '16:9'];
|
||||
errorHandle(ratioList.includes(ratio), `'aspectRatio' only accept ${ratioList.toString()} as parameters`);
|
||||
|
||||
player.rotate = 0;
|
||||
if (ratio === 'default') {
|
||||
player.aspectRatio = false;
|
||||
} else {
|
||||
const ratioArray = ratio.split(':');
|
||||
const { videoWidth, videoHeight } = $video;
|
||||
const { clientWidth, clientHeight } = $player;
|
||||
const videoRatio = videoWidth / videoHeight;
|
||||
const setupRatio = ratioArray[0] / ratioArray[1];
|
||||
if (videoRatio > setupRatio) {
|
||||
const percentage = (setupRatio * videoHeight) / videoWidth;
|
||||
setStyle($video, 'width', `${percentage * 100}%`);
|
||||
setStyle($video, 'height', '100%');
|
||||
setStyle($video, 'padding', `0 ${(clientWidth - clientWidth * percentage) / 2}px`);
|
||||
} else {
|
||||
const percentage = videoWidth / setupRatio / videoHeight;
|
||||
setStyle($video, 'width', '100%');
|
||||
setStyle($video, 'height', `${percentage * 100}%`);
|
||||
setStyle($video, 'padding', `${(clientHeight - clientHeight * percentage) / 2}px 0`);
|
||||
}
|
||||
}
|
||||
|
||||
$player.dataset.aspectRatio = ratio;
|
||||
notice.show = `${i18n.get('Aspect ratio')}: ${ratio === 'default' ? i18n.get('Default') : ratio}`;
|
||||
art.emit('aspectRatio', ratio);
|
||||
} else if (player.aspectRatio) {
|
||||
if (!ratio || ratio === 'default') {
|
||||
setStyle($video, 'width', null);
|
||||
setStyle($video, 'height', null);
|
||||
setStyle($video, 'padding', null);
|
||||
delete $player.dataset.aspectRatio;
|
||||
art.emit('aspectRatio', 'default');
|
||||
} else {
|
||||
const ratioArray = ratio.split(':');
|
||||
const { videoWidth, videoHeight } = $video;
|
||||
const { clientWidth, clientHeight } = $player;
|
||||
const videoRatio = videoWidth / videoHeight;
|
||||
const setupRatio = ratioArray[0] / ratioArray[1];
|
||||
if (videoRatio > setupRatio) {
|
||||
const percentage = (setupRatio * videoHeight) / videoWidth;
|
||||
setStyle($video, 'width', `${percentage * 100}%`);
|
||||
setStyle($video, 'height', '100%');
|
||||
setStyle($video, 'padding', `0 ${(clientWidth - clientWidth * percentage) / 2}px`);
|
||||
} else {
|
||||
const percentage = videoWidth / setupRatio / videoHeight;
|
||||
setStyle($video, 'width', '100%');
|
||||
setStyle($video, 'height', `${percentage * 100}%`);
|
||||
setStyle($video, 'padding', `${(clientHeight - clientHeight * percentage) / 2}px 0`);
|
||||
}
|
||||
$player.dataset.aspectRatio = ratio;
|
||||
}
|
||||
|
||||
notice.show = `${i18n.get('Aspect ratio')}: ${ratio === 'default' ? i18n.get('Default') : ratio}`;
|
||||
art.emit('aspectRatio', ratio);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,25 +1,37 @@
|
||||
import { errorHandle, def } from '../utils';
|
||||
|
||||
export default function flipMix(art, player) {
|
||||
const { $player } = art.template;
|
||||
const {
|
||||
template: { $player },
|
||||
i18n,
|
||||
notice,
|
||||
} = art;
|
||||
|
||||
def(player, 'flip', {
|
||||
get() {
|
||||
return $player.dataset.flip;
|
||||
},
|
||||
set(flip) {
|
||||
if (flip) {
|
||||
const flipList = ['normal', 'horizontal', 'vertical'];
|
||||
errorHandle(flipList.includes(flip), `'flip' only accept ${flipList.toString()} as parameters`);
|
||||
player.rotate = 0;
|
||||
if (flip === 'normal') {
|
||||
player.flip = false;
|
||||
} else {
|
||||
$player.dataset.flip = flip;
|
||||
art.emit('flip', flip);
|
||||
}
|
||||
} else {
|
||||
const flipList = [false, 'normal', 'horizontal', 'vertical'];
|
||||
errorHandle(flipList.includes(flip), `'flip' only accept ${flipList.toString()} as parameters`);
|
||||
|
||||
if (!flip || flip === 'normal') {
|
||||
delete $player.dataset.flip;
|
||||
art.emit('flip', 'normal');
|
||||
} else {
|
||||
$player.dataset.flip = flip;
|
||||
}
|
||||
|
||||
const word = flip.replace(flip[0], flip[0].toUpperCase());
|
||||
notice.show = `${i18n.get('Flip')}: ${i18n.get(word)}`;
|
||||
art.emit('flip', flip);
|
||||
},
|
||||
});
|
||||
|
||||
def(player, 'flipReset', {
|
||||
set(value) {
|
||||
if (value && player.flip) {
|
||||
const { flip } = player;
|
||||
player.flip = flip;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,26 +10,23 @@ export default function rotateMix(art, player) {
|
||||
def(player, 'rotate', {
|
||||
get: () => Number($player.dataset.rotate) || 0,
|
||||
set: (deg) => {
|
||||
const degList = [-270, -180, -90, 0, 90, 180, 270];
|
||||
const degList = [false, -270, -180, -90, 0, 90, 180, 270];
|
||||
errorHandle(degList.includes(deg), `'rotate' only accept ${degList.toString()} as parameters`);
|
||||
player.flip = false;
|
||||
player.aspectRatio = false;
|
||||
notice.show = `${i18n.get('Rotate')}: ${deg}°`;
|
||||
|
||||
if (deg) {
|
||||
const { videoWidth, videoHeight } = $video;
|
||||
const { clientWidth, clientHeight } = $player;
|
||||
const degFormat = deg < 0 ? deg + 360 : deg;
|
||||
|
||||
$player.dataset.rotate = deg;
|
||||
art.emit('rotate', deg);
|
||||
} else {
|
||||
if (!deg) {
|
||||
setStyle($video, 'width', null);
|
||||
setStyle($video, 'height', null);
|
||||
setStyle($video, 'padding', null);
|
||||
delete $player.dataset.rotate;
|
||||
art.emit('rotate', 0);
|
||||
} else {
|
||||
const { videoWidth, videoHeight } = $video;
|
||||
const { clientWidth, clientHeight } = $player;
|
||||
const degFormat = deg < 0 ? deg + 360 : deg;
|
||||
$player.dataset.rotate = deg;
|
||||
}
|
||||
|
||||
notice.show = `${i18n.get('Rotate')}: ${deg}°`;
|
||||
art.emit('rotate', deg);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user