Menu icon Foundation
Call scrollToLoc() from other JS?

Is it possible to utilize the scrollToLoc() from other JS? I have magellan and a sticky nav working nicely but there are other buttons/links on the page that I'd like to have perform the same action that the nav does currently. 

I found Foundation.Magellan.prototype.scrollToLoc() but it seems to be dependent on Magellan knowing a lot more ...

Thanks!

Magellan scrollToLoc

Is it possible to utilize the scrollToLoc() from other JS? I have magellan and a sticky nav working nicely but there are other buttons/links on the page that I'd like to have perform the same action that the nav does currently. 

I found Foundation.Magellan.prototype.scrollToLoc() but it seems to be dependent on Magellan knowing a lot more ...

Thanks!

Jason Froderman over 3 years ago

I've resorted to the following outside of Magellan. Just wondering if I'm going to run into any weird cross browser stuff trying to have multiple things solving smooth scrolling at once.

$(function() {
  $('a[href*="#"]:not([href="#"])').click(function() {
    console.log(this);
    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) {
        $('html, body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});