Reputation: 223
i have the following code:
Template.home.onRendered(function() {
var scrollElem = $("#scroll");
scrollElem.scrollTo("max", 500);
})
I'm also using jquery-scrollto package for meteor. It fires only once when page is loaded but when i refresh it never fires again. I know that onRendered runs only when element is changed but what should i use then? I tried to put this code in Meteor.startup() and $(window).load() but it doesn't work either.
I fixed it by adding setTimeout()
function but what if user's internet connection is slow? It wont fire. Any solutions for this?
Upvotes: 1
Views: 911
Reputation: 4820
If not already doing so, try using the newer version of the package.
It may be that your #scroll
element is not loaded yet. You could try using the load()
method:
Template.home.onRendered(function() {
var scrollElem = $("#scroll");
scrollElem.load(function () {
scrollElem.scrollTo("max", 500);
});
})
If it still does not work, try using the plugin directly instead of using a purely intermediary meteor package. Uninstall the package:
meteor remove johnantoni:meteor-scrollto
In your head code, for example client/main.html:
<head>
<script src="//cdn.jsdelivr.net/jquery.scrollto/2.1.0/jquery.scrollTo.min.js"></script>
</head>
Or, if you want to keep the lib in your app, download it and put it in public/jquery-scrollto/, then in the head:
<head>
<script src="/jquery-scrollto/jquery.scrollTo.min.js"></script>
</head>
Upvotes: 1