jQuery Smooth Scrolling from CSS-Tricks

As it says at the top, “Performs a smooth page scroll to an anchor on the same page.” The beauty of this code snippet is that it just works, everywhere across the site: anywhere there’s a link to an anchor on the same page, that becomes a smooth JavaScript scroll rather than a choppy instantaneous jump.

To use it, enqueue it from your theme’s functions.php. You’ll probably also want to work with the fact that it uses $ to mean “jQuery”—either by simply changing $ to jQuery throughout the code, or by doing the standard $ mapping in WordPress.

Add a Comment

Your email address will not be published.