[F] Fix margin calculation
This commit is contained in:
+11
-8
@@ -18,24 +18,27 @@ export default class Responsive
|
|||||||
*/
|
*/
|
||||||
getNumberOnScreen(currentWidth: number = document.documentElement.clientWidth)
|
getNumberOnScreen(currentWidth: number = document.documentElement.clientWidth)
|
||||||
{
|
{
|
||||||
|
let margin = vhToPx(this.margin) * 2;
|
||||||
|
let min = vhToPx(this.minWidth);
|
||||||
|
|
||||||
// Screen too small
|
// Screen too small
|
||||||
if (currentWidth < vhToPx(this.margin) * 2 + vhToPx(this.minWidth)) return 1;
|
if (currentWidth > (margin + min) * 6) return 6;
|
||||||
|
|
||||||
// Loop through all the possible numbers on screen
|
// Loop through all the possible numbers on screen
|
||||||
[1, 2, 3, 4, 5, 6].reverse().forEach(i =>
|
for (let i of [1, 2, 3, 4, 5, 6].reverse())
|
||||||
{
|
{
|
||||||
// Calculate margin width
|
// Calculate margin width
|
||||||
let margins = vhToPx(this.margin) * (i + 1);
|
let margins = margin * i;
|
||||||
|
|
||||||
// Calculate block width
|
// Calculate block width
|
||||||
let blockWidth = (currentWidth - margins) / i;
|
let blockWidth = (currentWidth - margins) / i;
|
||||||
|
|
||||||
// Return block width
|
// Return block width
|
||||||
if (blockWidth > vhToPx(this.minWidth)) return i;
|
if (blockWidth > min) return i;
|
||||||
});
|
}
|
||||||
|
|
||||||
// Screen too big
|
// Screen too small
|
||||||
return 6;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,7 +50,7 @@ export default class Responsive
|
|||||||
getBlockWidth(currentWidth: number = document.documentElement.clientWidth)
|
getBlockWidth(currentWidth: number = document.documentElement.clientWidth)
|
||||||
{
|
{
|
||||||
let count = this.getNumberOnScreen(currentWidth);
|
let count = this.getNumberOnScreen(currentWidth);
|
||||||
return (currentWidth - vhToPx(this.margin) * (count + 1)) / count;
|
return (currentWidth - vhToPx(this.margin) * count * 2) / count - 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user