But it’s not working. The / route also uses the landingPage template. So the goal here is, if a user navigates to /get-started, they’re still on the landing page but it’ll jump them down. (and yes, I realize I need to programatically get the ID position and jump to that… the hardcoded 3000 is just for testing)
Not sure why it doesn’t work within the route but I guess you could stick it all in the onRendered function of the template. Not able to check the below at the moment so it might have a few typos in but I think the concept should work. Getting the route name like that with Iron Router is reactive I believe so it’ll rerun on change.
Template.templateName.onRendered(function() {
var instance = this;
instance.autorun(function() {
var routeName = Router.current().route.getName();
if (routeName === 'get-started') {
$('html,body').scrollTop(3000);
}
});
});
this.subscriptionsReady() couldnt help you in this case. If your DOM depends on sub data then you should know that this.subscriptionsReady() > Tracker.afterFlush > scrollTop() isnt the same as this.subscriptionsReady() > DOM Rendered (page has its real height) > scrollTop()
So you should separate the sub and the view that you want to scroll on rendered. I mean your logic have to looks like:
render parent template with subscribtions
wait for subs are ready inside parent
render child template from parent (just use Blaze {{#if <...>}} {{> childTemplate}} {{/if}})
scroll the page on child template with onRendered with afterFlush
This is the one thing I dislike about Meteor. The order of processing/rendering is very unclear to me. It shouldn’t take me more than an hour to figure out how to do this.
Are you shure it works from console after your page is ready? Could it be that something else does matter on the page height? I’ve tried a clean meteor project and it works man!
The scrolling definitely works if I run it from the console after the page is already loaded. I dunno, this one is super confusing and I can’t seem to figure it out. It’s a major bummer
It could matters nothing but try to set a breakpoint in onRendered and on code stops run scroll from console. I’ve hade similar with adding a class for transition with min-width