Skip to content

Commit db8c9f4

Browse files
committed
scroll to selected instantly
1 parent b88b1c8 commit db8c9f4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

colors/colors-w.htm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
}
1818
}
1919

20+
/** Selects a random item from an array **/
2021
function pick(items) {
2122
return items[Math.floor(Math.random() * items.length)];
2223
}
@@ -123,11 +124,19 @@
123124
this.container.style.width = `${(width * count)}px`;
124125

125126
let index = 0;
127+
let selected = undefined;
128+
let selectedLeft = undefined;
126129
for (const child of [...this.container.children]) {
130+
if (child.matches(".selected")) {
131+
selected = child;
132+
selectedLeft = index * width;
133+
}
127134
console.log(child);
128135
child.style.left = `${index * width}px`;
129136
++index;
130137
}
138+
139+
this.scroller.scroll({ left: selectedLeft, behavior: "instant" });
131140
}
132141

133142
contract() {
@@ -320,7 +329,7 @@
320329
`
321330
;
322331

323-
document.querySelector(".copyText").onclick = () => copyText(text);
332+
document.querySelector(".copyText").onclick = () => copyText(text);
324333
})();
325334
</script>
326335
<style>
@@ -391,7 +400,7 @@
391400
display: block;
392401
width: var(--width);
393402
height: var(--height);
394-
transition: width 0.6s ease;
403+
/* transition: width 0.6s ease; */
395404
}
396405

397406
expand-children>.scroller>.container>* {

0 commit comments

Comments
 (0)