My question is simple, but I'm struggling to find the answer. I use a meteorite to create a website. With my meteorite, I use an iron router to navigate my AKA template pages. My head always stays the same. I only change the body, changing the template that is contained in the body using an iron router. I have a page containing anchor tags with identifiers, I want the page to automatically scroll to a specific anchor on my web page when my template changes due to the user navigating to this page . Unfortunately, I can only provide code snippets, because I am creating a web page for the company and do not want information leakage. I think there will be enough code fragments.
I tried the onAfterRun iron router:
Router.map(function(){
this.route("cpdEvents", {
path: "cpd.html#events",
onAfterRun: function() {
e.preventDefault();
$('html, body').animate({
scrollTop: $("a[name=events]").offset().top
}, 600);
}
});
});
:
if (Meteor.isClient) {
Template.cpd.rendered = function (){
e.preventDefault();
$('html, body').animate({
scrollTop: $("a[name=events]").offset().top
}, 600);
}
}
, , . html cpd.html, . JavaScript .
index.html
<head>
<meta ..... />
<title></title>
</head>
<body>
{{> index}}
</div>
</body>
cpd.html:
<template name="cpd">
....
<a name="events"></a>
....
</template>
:
Meteor jquery-, , jquery .
, , HTML. , "#" URL-. www.example.com/cpdEvents#events