Get started with jquery-hashchange CDN

(MIT OR GPL-2.0) licensed

JQuery HashChange plugin detects and responds to browsers hash change events.

Tags:
  • jquery
  • history

Stable version

Copied!

How to start using jquery-hashchange CDN


$(document).ready(function() {
  // Initialize the plugin
  $.fn.hashchange.bind('hashchange', function() {
    // Handle the hashchange event
    var newHash = location.hash;

    if (newHash === '#about') {
      // Show about section when the URL hash is #about
      $('html, body').animate({
        scrollTop: $('#about').offset().top
      }, 500);
    } else if (newHash === '#services') {
      // Show services section when the URL hash is #services
      $('html, body').animate({
        scrollTop: $('#services').offset().top
      }, 500);
    }
  });

  // Trigger the plugin to initialize with the current URL hash
  $.fn.hashchange.trigger('hashchange');
});
Copied!
Copied!

All versions