Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 1009 Bytes

auto-scroll.md

File metadata and controls

36 lines (27 loc) · 1009 Bytes

Auto-scroll to the top of the page after navigation

FlowRouter causes the page to remain at the same scroll position on navigation between routes (which people are often surprised by). Little snipped below would fix this behavior to more common, when each page loaded at the top of the scrolling position.

Originated from #9.

import { FlowRouter } from 'meteor/ostrio:flow-router-extra';

const scrollToTop = () => {
  setTimeout(() => {
    if (!window.location.hash) {
      (window.scroll || window.scrollTo || function (){})(0, 0);
    }
  }, 25);
};

FlowRouter.triggers.enter([scrollToTop]);

With jQuery animation:

import { $ }          from 'meteor/jquery';
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';

const scrollToTop = () => {
  setTimeout(() => {
    if (!window.location.hash) {
      $('html, body').animate({scrollTop: 100});
    }
  }, 25);
};

FlowRouter.triggers.enter([scrollToTop]);