Files
ArtPlayer/packages/artplayer/src/player/autoHeightMix.js
T
2022-01-07 17:38:10 +08:00

33 lines
1.1 KiB
JavaScript

import { setStyle, hasClass, addClass, removeClass, def } from '../utils';
export default function autoHeightMix(art) {
const {
option,
template: { $container, $video },
} = art;
const heightCache = $container.style.height;
def(art, 'autoHeight', {
get() {
return hasClass($container, 'art-auto-height');
},
set(value) {
if (value) {
const { clientWidth } = $container;
const { videoHeight, videoWidth } = $video;
const height = videoHeight * (clientWidth / videoWidth);
setStyle($container, 'height', height + 'px');
addClass($container, 'art-auto-height');
art.autoSize = option.autoSize;
art.emit('autoHeight', height);
} else {
setStyle($container, 'height', heightCache);
removeClass($container, 'art-auto-height');
art.autoSize = option.autoSize;
art.emit('autoHeight');
}
},
});
}