Sha256: 82b19494444f08d4b32a05cf1c7426fd487875fcd37dccf830ffa34d67c99f7e

Contents?: true

Size: 1.29 KB

Versions: 70

Compression:

Stored size: 1.29 KB

Contents

const SmoothScroll = () => {
  // Select all links with hashes
  $('a[href*="#"]')
    // Remove links that don't actually link to anything
    .not('[href="#"]')
    .not('[href="#0"]')
    .click(function(event) {
      // On-page links
      if (
        location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
        &&
        location.hostname == this.hostname
      ) {
        // Figure out element to scroll to
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
        // Does a scroll target exist?
        if (target.length) {
          // Only prevent default if animation is actually gonna happen
          event.preventDefault();
          $('html, body').animate({
            scrollTop: target.offset().top
          }, 500, function() {
            // Callback after animation
            // Must change focus!
            var $target = $(target);
            $target.focus();
            if ($target.is(":focus")) { // Checking if the target was focused
              return false;
            } else {
              $target.attr('tabindex','-1'); // Adding tabindex for elements not focusable
              $target.focus(); // Set focus again
            };
          });
        }
      }
    }
  );
}

$(SmoothScroll);

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
futuro-0.9.9 assets/js/footer/custom/4_SmoothScroll.js
futuro-0.9.8 assets/js/footer/custom/SmoothScroll.js
futuro-0.9.7 assets/js/footer/custom/SmoothScroll.js
futuro-0.9.6 assets/js/footer/custom/SmoothScroll.js
futuro-0.9.5 assets/js/footer/custom/SmoothScroll.js
futuro-0.9.4 assets/js/footer/custom/SmoothScroll.js
futuro-0.9.3 assets/js/footer/custom/SmoothScroll.js
futuro-0.9.2 assets/js/footer/custom/SmoothScroll.js
futuro-0.9.1 assets/js/footer/custom/SmoothScroll.js
futuro-0.9.0 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.9 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.8 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.7 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.6 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.5 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.4 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.3 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.2 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.1 assets/js/footer/custom/SmoothScroll.js
futuro-0.8.0 assets/js/footer/custom/SmoothScroll.js