Код: Выделить всё
/**
* Whether the element can be scrolled.
* @param {HTMLElement} el The element.
* @param {boolean} vertical Whether the scroll is vertical.
* @param {boolean} plus Whether the scroll is positive (down or right).
* @returns {boolean} Whether the element can be scrolled.
*/
function canScroll(el, vertical = true, plus = true) {
const style = window.getComputedStyle(el);
const overflow = vertical ? style.overflowY : style.overflowX;
const scrollSize = vertical ? el.scrollHeight : el.scrollWidth;
const clientSize = vertical ? el.clientHeight : el.clientWidth;
const scrollPos = vertical ? el.scrollTop : el.scrollLeft;
const isScrollable = scrollSize > clientSize;
const canScrollFurther = plus
? scrollPos + clientSize < scrollSize
: scrollPos > 0;
return (
isScrollable &&
canScrollFurther &&
!overflow.includes("visible") &&
!overflow.includes("hidden")
);
}
Как я могу улучшить эту функцию CanScroll , чтобы она могла правильно обработать данное пример?
Подробнее здесь: https://stackoverflow.com/questions/792 ... scrollable
Мобильная версия