enrique42
2/24/2017 - 1:12 PM

Scroll por âncora, animado

Animação de rolagem para links por scroll

//Pendura a função nos links que usarão as âncoras
$(".js-navscroll").on('click', navegaScroll);

// Função
function navegaScroll(event) {
  var dest = 0;
  var offset = 0;
  var speed = 600;
      
  if( hashTagActive != this.hash) {
    event.preventDefault();

    if ($(this.hash).offset().top > $(document).height() - $(window).height()) {
      dest = $(document).height() - $(window).height() + offset;
    } else {
      dest = $(this.hash).offset().top + offset;
    }

    $('html,body').animate({
      scrollTop: dest
    }, speed);
    
    hashTagActive = this.hash;
  }
}