Simplebar: VueJS - Scroll to Top

Created on 13 Apr 2019  路  1Comment  路  Source: Grsmto/simplebar

Hi, I am looking for a way to reset the scroll position or scroll to top. I found a way using plain JS.

const el = new SimpleBar(document.getElementById('layout'));
el.contentEl.scrollTop = 0;

But how can I do that in vue??

Your environment

| Software | Version(s) |
| ---------------- | ---------- |
| simplebar-vue | latest
| Browser | Chrome 73.0.3683.1
| npm/Yarn | npm 6.4.1
| Operating System | Windows 10

Most helpful comment

Never mind. I figured it out. Here is the solution if someone is looking for.

First you have set a reference to the scrollbar.

<simplebar ref="Scroller" >
            ....content
</simplebar>

Then you can access the SimpleBar instance like this

const ref = this.$refs.Scroller;
const el = ref.$el.SimpleBar;
el.contentEl.scrollTop = 0

You are welcome :)

>All comments

Never mind. I figured it out. Here is the solution if someone is looking for.

First you have set a reference to the scrollbar.

<simplebar ref="Scroller" >
            ....content
</simplebar>

Then you can access the SimpleBar instance like this

const ref = this.$refs.Scroller;
const el = ref.$el.SimpleBar;
el.contentEl.scrollTop = 0

You are welcome :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adsim picture adsim  路  5Comments

EmilMoe picture EmilMoe  路  4Comments

TheeOhioState picture TheeOhioState  路  6Comments

apopelyshev picture apopelyshev  路  7Comments

Blackleones picture Blackleones  路  3Comments