mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-19 11:21:20 -08:00
add floatCeil
This commit is contained in:
1 parent
18ca81e2ed
commit
a244879a3e
4 files changed
+15
-6
No files matched your search
@@ -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}%`);
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
Reference in new issue
Block a user