question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

programmatic smooth scrolling

See original GitHub issue

🔎 Usage Questions

Is it possible to programmatically smooth scroll? I’m trying to get a “scroll to top” button working without jumping right back to the top all jittery and ugly -like.

My current code:

 $('.go-top').click(function(event) {
    event.preventDefault();
    let bodyscrollTop = simpleBar.getScrollElement()
    bodyscrollTop.scrollTop = 0
    // let bodyscrollTopTop = bodyscrollTop.scrollTop
    // $('html, body').animate({bodyscrollTopTop: 0}, 300);
})

That works, but jumps immediately back to the top, which isnt great UX…

The commented out portion is how I would expect to be able to do it smoothly, however that doesnt work at all. No Action. It does not generate any error messages either…

I’ve tried the scrollIntoView() method as well. That doesnt work either.

Is this simply not possible with simplebar or am I missing something?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Rod911commented, Jul 13, 2021

You could also try

[data-simplebar]:not(.simplebar-dragging) .simplebar-content-wrapper {
	scroll-behavior: smooth;
}
0reactions
Rod911commented, Aug 3, 2022

@darkmodeee Codepen See, works like a charm, I find the link tag works better for nested scrollbars as it scrolls both parent and child to get the element into view

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Implement Smooth Scrolling With CSS & JavaScript
Learn how to implement smooth scrolling in web pages. Start with a pure CSS solution, then a common jQuery approach.
Read more >
Smooth scroll without the use of jQuery - Stack Overflow
Scrolling an element requires changing its scrollTop value over time. For a given point in time, calculate a new scrollTop value. To animate...
Read more >
Programmatic scrolling - Vuetify
This method supports several different types of target selectors, and options including smooth scrolling using built-in easing functions.
Read more >
Native Smooth Scroll with pure CSS and JS - Lucas Paganini
scroll -behavior: smooth applies a smooth transition when a scroll event is programmatically triggered. I say "programmatically triggered" because it's not going ...
Read more >
Smooth Scrolling With JavaScript - Better Programming
A technical look at creating a library from scratch · Detecting the element type · Detect how much to scroll · Triggering the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found