MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / ScrollBar

Function ScrollBar

src/components/scrollbar/index.js:30–316  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

28 * @returns {Scrollbar & HTMLElement}
29 */
30export default function ScrollBar(options) {
31 if (!options || !options.parent) {
32 throw new Error("ScrollBar.js: Parent element required.");
33 }
34
35 const { placement = "right" } = options;
36 const $cursor = tag("span", {
37 className: "scroll-cursor",
38 style: {
39 top: 0,
40 left: 0,
41 },
42 });
43 const $thumb = tag("span", {
44 className: "thumb",
45 });
46 const $container = tag("div", {
47 className: "container",
48 children: [$cursor, $thumb],
49 });
50 const $scrollbar = tag("div", {
51 className: `scrollbar-container ${placement}`,
52 child: $container,
53 });
54 const config = {
55 passive: false,
56 };
57 const TIMEOUT = 2000;
58 const isVertical = placement === "right" || placement === "left";
59 const observer = new MutationObserver(observerCallback);
60 let scroll = 0;
61 let touchStartValue = {
62 x: 0,
63 y: 0,
64 };
65 let scrollbarSize = 20;
66 let thumbHeight = options.thumbHeight ?? 50;
67 let height;
68 let width;
69 let rect;
70 let scrollbarTimeoutHide;
71 let scrollbarTimeoutRemove;
72 let onshow;
73 let onhide;
74 let touchStarted = false;
75
76 if (options.width) scrollbarSize = options.width;
77
78 setWidth(scrollbarSize);
79 setThumbHeight(thumbHeight);
80 $scrollbar.onScroll = options.onscroll;
81 $scrollbar.onScrollEnd = options.onscrollend;
82 $thumb.addEventListener("touchstart", touchStart, config);
83 $thumb.addEventListener("mousedown", touchStart, config);
84 window.addEventListener("resize", resize);
85 observer.observe($cursor, {
86 attributes: true,
87 });

Callers 1

EditorManagerFunction · 0.85

Calls 3

setWidthFunction · 0.85
setThumbHeightFunction · 0.85
definePropertyMethod · 0.80

Tested by

no test coverage detected