A javascript scrollbar plugin which hides native scrollbars, provides custom styleable overlay scrollbars and keeps the native functionality and feeling.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Core functionality for creating and managing OverlayScrollbars instances, including constructor usage patterns and instance lifecycle management.
function OverlayScrollbars(
target: Element | NodeList | string,
options?: OverlayScrollbarsOptions,
extensions?: OverlayScrollbarsExtensions
): OverlayScrollbarsInstance | OverlayScrollbarsInstance[];Parameters:
target - Element(s) to apply scrollbars to. Can be a single Element, NodeList, or selector stringoptions - Configuration options object (optional)extensions - Extensions to initialize with the instance (optional)Returns: Single instance for single elements, array of instances for multiple elements
// Initialize with minimal options
const instance = OverlayScrollbars(document.querySelector('.content'), {});
// Initialize with configuration
const instance = OverlayScrollbars(document.getElementById('main'), {
className: "os-theme-dark",
resize: "both",
scrollbars: {
autoHide: "leave",
autoHideDelay: 1000
}
});// Initialize multiple elements with same options
const instances = OverlayScrollbars(document.querySelectorAll('.scrollable'), {
scrollbars: {
visibility: "auto"
}
});
// Access individual instances
instances.forEach((instance, index) => {
console.log(`Instance ${index} initialized`);
});// Using selector strings
const instances = OverlayScrollbars('.content, .sidebar', {
className: "custom-theme"
});const instance = OverlayScrollbars(element, {
scrollbars: { autoHide: "scroll" }
}, {
// Extension configuration
customExtension: { option: true }
});You can retrieve existing instances without reinitializing:
// Get existing instance (returns undefined if not initialized)
const existingInstance = OverlayScrollbars(element);
// Get multiple existing instances
const existingInstances = OverlayScrollbars(document.querySelectorAll('.content'));// Initialize only elements that match condition
const instances = OverlayScrollbars(document.querySelectorAll('.content'), '!');
// Returns only valid, non-destroyed instances
// Initialize with custom condition function
const instances = OverlayScrollbars(
document.querySelectorAll('.content'),
(element, existingInstance) => {
// Return true to include this element
return element.scrollHeight > element.clientHeight;
}
);interface OverlayScrollbarsInstance {
getState(property?: string): OverlayScrollbarsState | any;
getElements(elementName?: string): OverlayScrollbarsElements | Element;
}const instance = OverlayScrollbars(element, {});
// Get complete state
const state = instance.getState();
console.log(state.destroyed); // false
console.log(state.sleeping); // false
console.log(state.autoUpdate); // auto-update status
// Get specific state property
const isDestroyed = instance.getState('destroyed');// Get all internal elements
const elements = instance.getElements();
console.log(elements.target); // Original target element
console.log(elements.host); // Host wrapper element
console.log(elements.viewport); // Viewport element
console.log(elements.content); // Content wrapper element
// Get specific element
const viewport = instance.getElements('viewport');Put instances to sleep to disable automatic updates:
OverlayScrollbarsInstance.prototype.sleep(): OverlayScrollbarsInstance;// Put instance to sleep (disables auto-updates)
instance.sleep();
// Wake up with manual update
instance.update();interface OverlayScrollbarsState {
destroyed: boolean;
sleeping: boolean;
autoUpdate: boolean | null;
widthAuto: boolean;
heightAuto: boolean;
padding: { t: number; r: number; b: number; l: number };
overflowAmount: { x: number; y: number };
hideOverflow: { x: boolean; y: boolean };
hasOverflow: { x: boolean; y: boolean };
contentScrollSize: { width: number; height: number };
viewportSize: { width: number; height: number };
hostSize: { width: number; height: number };
}
interface OverlayScrollbarsElements {
target: Element;
host: Element;
padding: Element;
viewport: Element;
content: Element;
scrollbarHorizontal: { scrollbar: Element; track: Element; handle: Element };
scrollbarVertical: { scrollbar: Element; track: Element; handle: Element };
scrollbarCorner: Element;
}Install with Tessl CLI
npx tessl i tessl/npm-overlayscrollbars