I'm currently learning to use Meteor, and am having trouble implementing the jQuery 'animate' function in one of my templates. I'm using this great boilerplate https://github.com/matteodem/meteor-boilerplate as an example, and am trying to get the following working:
home.html
<template name="home">
<div id="front-page">
<div class="container">
<div class="page-bottom-nav">
<div class="row">
{{#each feature}}
<div class="col-xs-6 col-md-3">
<div class="thumbnail aligned center home-page-nav-boxes">
<a href="{{path}}" class="link unstyled no-underline {{color}} padding wrapper">
<i class="glyphicon {{glyphicon}} image-links-home-page"></i>
<div class="headline text-links-home-page">{{text}}</div>
</a>
</div>
</div>
{{/each}}
</div>
</div>
</div>
</div>
<div id="about">
About
</div>
<div id="explore">
Explore
</div>
<div id="blog">
Blog
</div>
<div id="press-contact">
Press/Contact
</div>
</template>
home.js
Template.home.helpers({
'feature' : function () {
return [
{ 'text' : 'About', 'glyphicon' : 'glyphicon-sunglasses', 'color' : 'hover-yellow', 'path' : '#about' },
{ 'text' : 'Explore', 'glyphicon' : 'glyphicon-road', 'color' : 'hover-red', 'path' : '#explore' },
{ 'text' : 'Blog', 'glyphicon' : 'glyphicon-pencil', 'color' : 'hover-blue', 'path' : '#blog' },
{ 'text' : 'Press/Contact', 'glyphicon' : 'glyphicon-envelope', 'color' : 'hover-green', 'path' : '#press-contact' }
];
},
});
Template.home.events ({
});
Template.home.rendered = function () {
// @see: http://stackoverflow.com/questions/5284814/jquery-scroll-to-div
$('a[href*=#]:not([href=#])').click(function (event) {
alert("Content has been clicked");
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
console.log(target);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
event.preventDefault();
console.log(target.offset().top);
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
return true;
});
};
home.less
@import 'base';
#main {
.image-links-home-page.glyphicon {
font-size: @font-size-giant;
}
.hover-yellow:hover {
color: yellow;
}
.hover-green:hover {
color: green;
}
.hover-red:hover {
color: red;
}
.hover-blue:hover {
color: blue;
}
#front-page {
height: 100%;
width: 100%;
background-image: url('images/mt-cook.jpg');
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-position: fixed;
position: relative;
}
.page-bottom-nav {
bottom: 0;
position: absolute;
width: 90%;
padding-left: @padding-enormous-horizontal;
padding-right: @padding-enormous-horizontal;
}
.home-page-nav-boxes {
padding: @padding-giant-vertical;
opacity: 0.6;
transition: 0.7s color;
}
.text-links-home-page {
font-size: @font-size-large;
padding-top: @padding-large-vertical;
}
.navbar.past-front-page {
background-color:#fff;
color:#444;
opacity: 0.5;
}
#about {
height: 100%;
background-color: yellow;
}
#explore {
height: 100%;
background-color: red;
}
#blog {
height: 100%;
background-color: blue;
}
#press-contact {
height: 100%;
background-color: green;
}
}
These files are all in the client
folder within my app tree. The console.log
and alert
debugs work as expected, but no scrolling takes place...
Thanks in advance for the help, and do let me know if I'm missing something completely here!