Lag when using CSS smooth scroll-behavior
Opened this issue · 8 comments
Just noticed that when using animate-scroll.js in conjunction with CSS scroll-behavior: smooth
(applied to the html tag) then there's a noticable lag before starting the animation, about 1-2 seconds on a longer site.
Is this something you can fix, or should we use either CSS or animate-scroll?
SlimJet (Chromium):
Version 18.0.1.0 (based on Chromium 64.0.3282.119) (Official Build) (32-bit)
On the demo page if you add scroll-behavior: smooth
to the HTML then scroll either stops working or there's a lag:
http://sunmockyang.github.io/animate-scroll-js/demo/
The issue seems to be present in Chromium only, in Firefox it works fine.
Either solution would be OK to me. I think that if someone uses AnimateScroll with CSS smooth scroll he does it with a purpose (to achieve something that isn't possible with CSS, eg. clicking on a div instead on an anchor to scroll to a target). So in this case disabling CSS smooth scroll while the js scroll takes place would be preferrable imo.
Because you don't know what element is set to smooth scroll with CSS, I guess toggling a class on html would be the best, and the user can manually set scroll-behavior to auto if he needs to eg:
html * { scroll-behavior: auto; }
So on starting the js scroll add a class eg. animatescroll-on
and remove on finish. This is just a quick idea, perhaps there is a better one.
Hmmm that's a little too ham handed I think since there's no easy way to see which element has smooth scrolling turned on (at least that I'm aware of). Actually I should look into the "OnScroll" API and see if there's a way to differentiate the browser affecting scroll or the user affecting it
Anyway, I would add a sentence to the Notes in the readme about this issue.