LouisWhit
4/25/2018 - 8:44 PM

Anchor tag linking with smooth scroll

The script detects if an anchor tag is on the page or if the anchor tag appears in the URL. The script then properly executes the animation to the target anchor.

$('a[href*="#"]').not('[href="#"]').not('[href="#0"]').on('click', function(event) {
  if (
    location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') 
    && 
    location.hostname == this.hostname
  ) {
    var target = $(this.hash);
    target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
    if (target.length) {
      event.preventDefault();
      $('html, body').animate({
        scrollTop: target.offset().top
      }, 1000, function() {
      });
    }
  }
});
$(".<?php echo $brand;?>StructureBand").each(function(index, el) {
 $(this).attr('id', 'band-'+index);   
});