Skip to content

Commit a096916

Browse files
committed
add preview for scrollbar generator
1 parent 6f5f8a8 commit a096916

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,30 @@ <h1>Input Range</h1>
13341334

13351335
<!-- Custom Scroll Generator -->
13361336
<div data-content="scroll">
1337+
<!-- custom scroll generator -->
1338+
<h2>Preview</h2>
1339+
<br />
1340+
<div id="scroll-preview">
1341+
<p>
1342+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
1343+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
1344+
enim ad minim veniam, quis nostrud exercitation ullamco laboris
1345+
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
1346+
in reprehenderit in voluptate velit esse cillum dolore eu fugiat
1347+
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
1348+
sunt in culpa qui officia deserunt mollit anim id est laborum.
1349+
</p>
1350+
<p>
1351+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
1352+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
1353+
enim ad minim veniam, quis nostrud exercitation ullamco laboris
1354+
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
1355+
in reprehenderit in voluptate velit esse cillum dolore eu fugiat
1356+
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
1357+
sunt in culpa qui officia deserunt mollit anim id est laborum.
1358+
</p>
1359+
</div>
1360+
<br />
13371361
<div class="input">
13381362
<label for="color" class="color">
13391363
Track Color

src/pages/scroll.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,63 @@ function copyHandler(values: Values) {
8383
}
8484

8585
export function scrollGenerator() {
86+
const previewElement = document.getElementById(
87+
'scroll-preview'
88+
) as HTMLElement;
89+
90+
function applyPreviewStyles(values: Values) {
91+
if (!previewElement) return;
92+
93+
// Apply styles directly to the preview element
94+
previewElement.style.setProperty('--scrollbar-width', `${values.width}px`);
95+
previewElement.style.setProperty(
96+
'--scrollbar-track-color',
97+
values.trackColor
98+
);
99+
previewElement.style.setProperty(
100+
'--scrollbar-thumb-color',
101+
values.thumbColor
102+
);
103+
previewElement.style.setProperty(
104+
'--scrollbar-thumb-hover-color',
105+
values.hoverColor
106+
);
107+
108+
const styleTag = document.createElement('style');
109+
styleTag.id = 'scroll-preview-style';
110+
styleTag.innerHTML = `
111+
#scroll-preview::-webkit-scrollbar {
112+
width: var(--scrollbar-width);
113+
}
114+
#scroll-preview::-webkit-scrollbar-track {
115+
box-shadow: inset 0 0 5px var(--scrollbar-track-color);
116+
}
117+
#scroll-preview::-webkit-scrollbar-thumb {
118+
background: var(--scrollbar-thumb-color);
119+
}
120+
#scroll-preview::-webkit-scrollbar-thumb:hover {
121+
background: var(--scrollbar-thumb-hover-color);
122+
}
123+
`;
124+
125+
document.head.appendChild(styleTag);
126+
}
127+
128+
function updatePreview() {
129+
applyPreviewStyles({
130+
trackColor: trackColor.value,
131+
thumbColor: thumbColor.value,
132+
hoverColor: hoverColor.value,
133+
width: width.value,
134+
});
135+
}
136+
137+
[trackColor, thumbColor, hoverColor, width].forEach((input) => {
138+
input?.addEventListener('input', updatePreview);
139+
});
140+
141+
updatePreview();
142+
86143
getCodeButton?.addEventListener('click', () =>
87144
copyHandler({
88145
trackColor: trackColor.value,

src/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,14 @@ input[type='range']:focus::-moz-range-thumb {
12411241
color: var(--text-color);
12421242
}
12431243

1244+
#scroll-preview {
1245+
width: 300px;
1246+
height: 200px;
1247+
overflow-y: scroll;
1248+
border: 1px solid var(--text-color);
1249+
padding: 12px;
1250+
}
1251+
12441252
/* FOOTER SECTION */
12451253

12461254
footer {

0 commit comments

Comments
 (0)