1.0.3 • Published 8 months ago

optimal-gaps v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

OptimalGaps

Tiny script to find the optimal gaps between elements on viewport resize and make the last element overflow the container so the scrollbar makes sense to be there.

The gaps are calculated so the last element will be overflown for the given pixels or a percentage of it set on the option "offset".

The gaps will shrink in a linear calculation from the point that the container has an horizontal scrollbar, to the point of the "minViewportWidth" option. This linear calculation is the same used in this article of fluid typography


How to use:

import OptimalGaps from "optimalGaps.min.js";

const container = document.querySelector('.container');
const elements = document.querySelectorAll('.element');

const options = {
  container,
  elements,
  offset: '30%',
  initialGap: 20,
};

new OptimalGaps(options);

Parameters

ParametersRequiredTypes & accepted valuesDefaultDescription
containerYesDOMNode -nullThe contiaines that has the overflow propertie
elementsYesNodeList -nullThe list of elements that will have the gap
offsetYesString '100px' or '10%'nullThe quantity of the las element that will be overflown
initialGapYesInt -nullThe gaps that will be set without calculations
breakpointStartNoInt -nullIf set the calculation will start from this point
containerClassNoString -'js-has-scroll'The class that will be added to the contianer when the gap is calculated
minimunGapNoInt -10The minimun gap that will be set on the calculations
minViewportWidthNoInt -360The size of the viewport when the calculation will stop and the minimun gap will set
cssCustomPropertyNoString -'--optimal-gap'The CSS custom property that will be set on the container that has the calculated gap
sidePaddingsNoInt -0The amount of padding in pixels that will be set in the container element with a CSS custom property: '--side-paddings'

Events

Coming soon

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago