kswedberg / jquery-smooth-scroll

Automatically make same-page links scroll smoothly
MIT License
1.97k stars 427 forks source link

Delay Before Scroll On Other Page? #93

Closed ArtinM closed 8 years ago

ArtinM commented 8 years ago

Hi,

I'm using the following code and it works really great on anchors on the same page. It also somewhat works when the anchor is on another page (e.g. page2.html#anchor), but it happens too quickly when it scrolls on different pages. Is it possible to make it when it loads another page with an anchor it waits a second or waits for page to fully load before it scrolls down to the anchor? I don't want this to affect and delay anchors on the same page, only when you're going to an anchor on a different page.

Thank you.

Current code: jQuery('body').smoothScroll({ delegateSelector: 'a', offset: -60, speed: 1000, });

  jQuery('button.scrollsomething').bind('click', function(event) {
    event.preventDefault();
    jQuery.smoothScroll({
      scrollElement: $('div.scrollme'),

      scrollTarget: '#findme'
    });
  });
  jQuery('button.scrollhorz').bind('click', function(event) {
    event.preventDefault();
    jQuery.smoothScroll({
      direction: 'left',
      scrollElement: $('div.scrollme'),
      scrollTarget: '.horiz'
    });

  });
LL782 commented 8 years ago

This is a possible repeat of https://github.com/kswedberg/jquery-smooth-scroll/issues/61 and you may also like to look at https://github.com/kswedberg/jquery-smooth-scroll/issues/68 first for an understanding of what's happening.

kswedberg commented 8 years ago

Thanks, @LL782!

Also, @ArtinM, I added an example here: https://github.com/kswedberg/jquery-smooth-scroll#smooth-scrolling-on-page-load

If you want to delay the smooth scrolling, you can put the code "for page-2.html" inside a setTimeout(fn, delay) or even just inside a $(window).on('load', fn) callback. (Using a function instead of fn and number of milliseconds instead of delay)

LL782 commented 8 years ago

Thanks @kswedberg. The example code is great. I think I'll use that in place of my previous suggestion.

kswedberg commented 8 years ago

Excellent! Glad I could help.