component-basepackage.src.dir-utils.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-webcomponents Show documentation
Show all versions of vaadin-webcomponents Show documentation
Mvnpm composite: Vaadin webcomponents
The newest version!
/**
* @license
* Copyright (c) 2021 - 2024 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
/**
* Get the scrollLeft value of the element relative to the direction
*
* @param {HTMLElement} element
* @param {string} direction current direction of the element
* @return {number} the scrollLeft value.
*/
export function getNormalizedScrollLeft(element, direction) {
const { scrollLeft } = element;
if (direction !== 'rtl') {
return scrollLeft;
}
return element.scrollWidth - element.clientWidth + scrollLeft;
}
/**
* Set the scrollLeft value of the element relative to the direction
*
* @param {HTMLElement} element
* @param {string} direction current direction of the element
* @param {number} scrollLeft the scrollLeft value to be set
*/
export function setNormalizedScrollLeft(element, direction, scrollLeft) {
if (direction !== 'rtl') {
element.scrollLeft = scrollLeft;
} else {
element.scrollLeft = element.clientWidth - element.scrollWidth + scrollLeft;
}
}