add floatCeil

This commit is contained in:
Harvey committed 2019-09-12 17:02:47 +08:00
1 parent 18ca81e2ed
commit a244879a3e
4 files changed
+15 -6

No files matched your search

+3 -3
View File
@@ -1,4 +1,4 @@
import { setStyle } from '../utils';
import { setStyle, floatCeil } from '../utils';
export default function resizeMix(art, player) {
const {
@@ -17,11 +17,11 @@ export default function resizeMix(art, player) {
const containerRatio = width / height;
$container.classList.add('artplayer-auto-size');
if (containerRatio > videoRatio) {
const percentage = ((height * videoRatio) / width) * 100;
const percentage = floatCeil(((height * videoRatio) / width) * 100, 1);
setStyle($player, 'width', `${percentage}%`);
setStyle($player, 'height', '100%');
} else {
const percentage = (width / videoRatio / height) * 100;
const percentage = floatCeil((width / videoRatio / height) * 100, 1);
setStyle($player, 'width', '100%');
setStyle($player, 'height', `${percentage}%`);
}
+4
View File
@@ -15,6 +15,10 @@ export function clamp(num, a, b) {
return Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
}
export function floatCeil(num, precision = 2) {
return Math.ceil(num * 10 ** precision) / 10 ** precision;
}
export function getExt(url) {
if (url.includes('?')) {
return getExt(url.split('?')[0]);