@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
21 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.scrollPercentage = void 0;
const MAX_PERCENTAGE = 100;
const scrollPercentage = (scrollableElement, proportionLimit = 1) => {
if (scrollableElement.scrollHeight > scrollableElement.clientHeight) {
// Calculate the hidden size of the content
const hiddenScroll = scrollableElement.scrollHeight - scrollableElement.clientHeight;
// Calculate the ratio for the displacement when scrolling
const proportion = scrollableElement.scrollHeight / scrollableElement.clientHeight;
// Calculates the proportional distance elapsed by the scroll
const scrollTop = proportion > proportionLimit
? scrollableElement.scrollTop * proportion
: scrollableElement.scrollTop / (proportion * 2);
// Calculate the proportional percentage that must be subtracted from the dimensions
return (scrollTop * MAX_PERCENTAGE) / hiddenScroll;
}
return 0;
};
exports.scrollPercentage = scrollPercentage;
//# sourceMappingURL=scrollPercentage.js.map