@slicemenice/jquery-smooth-anchor-scroll

1.1.2 • Public • Published

jQuery Smooth Anchor Scroll

Usage

Include jquery-smooth-anchor-scroll.js to add support for smooth anchor scrolling to your website.

Optionally: Configure the scrolling duration either globally or per link element.

// Include this before including jquery-smooth-anchor-scroll.js

( function() {

	$( document ).ready( function() {

		window.smoothAnchorScroll = window.smoothAnchorScroll || {};

		window.smoothAnchorScroll = {
			// 600ms is the default scrolling duration
			// this can also be a function returning a duration in milliseconds
			duration: 600
		};

	} );

} )();
// Scrolling duration per link element

<a href="#some-anchor" data-smooth-anchor-scroll-duration="200">Smooth scroll to anchor</a>

Optionally: Configure the scrolling offset

// Include this before including jquery-smooth-anchor-scroll.js

( function() {

	$( document ).ready( function() {

		window.smoothAnchorScroll = window.smoothAnchorScroll || {};

		window.smoothAnchorScroll = {
			// this can also be a function returning the offset in pixels
			offset: 80
		};

	} );

} )();

Release History

1.1.3

  • Replaced setting the url hash using history.replaceState if available.

1.1.2

  • Fixed reference to window object.

1.1.1

  • Exclude certain hash types.

1.1.0

  • Added beforeScroll and afterScroll hooks.

1.0.0

  • Initial version.

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @slicemenice/jquery-smooth-anchor-scroll

      Weekly Downloads

      1

      Version

      1.1.2

      License

      MIT

      Unpacked Size

      4.74 kB

      Total Files

      3

      Last publish

      Collaborators

      • slicemenice