Skip to content

Instantly share code, notes, and snippets.

@aliboy08
Last active August 6, 2025 05:18
Show Gist options
  • Select an option

  • Save aliboy08/57d78a773a930d40f8c0f0328c13dbc8 to your computer and use it in GitHub Desktop.

Select an option

Save aliboy08/57d78a773a930d40f8c0f0328c13dbc8 to your computer and use it in GitHub Desktop.
Horizontal Scroll Carousel
export function get_offset(element) {
if (!element.getClientRects().length) {
return { top: 0, left: 0 };
}
let rect = element.getBoundingClientRect();
let win = element.ownerDocument.defaultView;
return ({
top: rect.top + win.pageYOffset,
left: rect.left + win.pageXOffset
});
}
export function min_max(value, min, max) {
if( value < min ) return min;
if( value > max ) return max;
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment