CSSOM View Smooth Scroll API
Adds an optional argument to existing scroll APIs that specifies whether scrolling should be smooth. Also adds a CSS property for this.
4 comments
-
Mattia Astorino
commented
Chrome 61 will support this and the css scroll-behavior. Firefox already support that.
-
Arturo Coronel
commented
excellent!!!
-
Jonathan
commented
Just used in a project with jQuery fallback... Would be great to see it in more browsers! Maybe this snippet is helpful:
var nav_top = jQuery("#site-navigation").offset().top; // Element that you want to scroll to...
// Try to use native smooth scrolling
// Thanks: https://blog.hospodarets.com/native_smooth_scrolling
if('scrollBehavior' in document.documentElement.style){
window.scrollTo(
{"top": nav_top, "behavior": "smooth"}
)
} else {
jQuery('html, body').animate({
scrollTop: nav_top
}, 1000);
} -
Taylor Hunt
commented
This is especially nice from a user standpoint, because it obviates scroll-jacking that never works quite right.
From what I understand, current scroll methods recalculate style and relayout, so this would be a more performant way to achieve smooth scroll-tos.


