Skip to content

Commit

Permalink
fix(scroll): add setScrollTop and setScrollLeft
Browse files Browse the repository at this point in the history
  • Loading branch information
koory1st committed Feb 12, 2024
1 parent 1e7eaf4 commit b093a31
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
42 changes: 40 additions & 2 deletions docs/src/routes/component/scrollbar/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
function scroll({ detail }) {
value = detail.scrollTop;
}
let setScrollTop;
</script>

<h1>{$langFn('cscrollbar01010')}</h1>
Expand Down Expand Up @@ -143,17 +145,53 @@

<Example
code={`
<script>
let list4 = [];
for (let i = 0; i < 20; i++) {
list4.push(i);
}
let value = 0;
let innerRef;
$: max = innerRef ? innerRef.clientHeight - 380 : 0;
function scroll({ detail }) {
value = detail.scrollTop;
}
let setScrollTop;
@@@/script>
<SvelScrollbar always bind:setScrollTop height="400px" on:scroll={scroll}>
<div bind:this={innerRef}>
{#each list4 as item}
<p class="scrollbar-demo-item">{item}</p>
{/each}
</div>
</SvelScrollbar>
<SvelSlider
bind:value
{max}
on:input={() => {
setScrollTop(value);
}}
/>
`}
>
<SvelScrollbar always height="400px" on:scroll={scroll}>
<SvelScrollbar always bind:setScrollTop height="400px" on:scroll={scroll}>
<div bind:this={innerRef}>
{#each list4 as item}
<p class="scrollbar-demo-item">{item}</p>
{/each}
</div>
</SvelScrollbar>

<SvelSlider bind:value {max} />
<SvelSlider
bind:value
{max}
on:input={() => {
setScrollTop(value);
}}
/>
</Example>

<style>
Expand Down
9 changes: 9 additions & 0 deletions packages/scrollbar/src/lib/scrollbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
export let noresize = false;
export let always = false;
export let minSize = 20;
export function setScrollTop(v) {
wrapRef.scrollTop = v;
}
export function setScrollLeft(v) {
wrapRef.scrollLeft = v;
}
$: scrollbarClass = a2s(['svel-scrollbar', $$props.class]);
$: wrapClass = a2s(['svel-scrollbar__wrap', ['svel-scrollbar__wrap--hidden-default', !native]]);
Expand Down

0 comments on commit b093a31

Please sign in to comment.