i have this function:
<script type="text/javascript">
$('.infinite-container').waypoint('infinite', {
container: 'auto',
items: '.infinite-item',
more: '.infinite-more-link',
offset: 'bottom-in-view',
loadingClass: 'infinite-loading',
onBeforePageLoad: $.noop,
onAfterPageLoad: $.noop
});
</script>
and i want to call some other functions, for example i want to call this:
<script>
$(document).ready(function() {
$('.container').stickem();
});
</script>
and in order to call it i want to replace $.noop on the onAfterPageLoad event
would it look something like this?:
onAfterPageLoad: $.stickem()
super new to javascript/jquery if you cant tell.
asked Jun 2, 2013 at 23:46
user2360599
833 gold badges3 silver badges11 bronze badges
2 Answers 2
Wrap your code inside a function, which the plugin will call when the onAfterPageLoad event fires:
onAfterPageLoad: function() {
$('.container').stickem();
}
answered Jun 2, 2013 at 23:50
Fabrício Matté
70.3k27 gold badges135 silver badges168 bronze badges
Sign up to request clarification or add additional context in comments.
8 Comments
user2360599
that did it, thank you. another question though, would i be able to add more to that paticular function.
Fabrício Matté
Of course.
=] Anything inside the function callback will execute once the onAfterPageLoad event fires.user2360599
like for example something like this:
onAfterPageLoad: function() { $('.container').stickem(); !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs'); } Fabrício Matté
@user2360599 That will append a twitter script in the page after the
onAfterPageLoad has fired. I'm not sure whether it is best practice but it should work just fine as long as there are no syntax errors.user2360599
thank you, just tried it but got no luck. but thanks for your help!
|
You have to create a function and put your code inside that function. See below for an example:
function stickem(){
// your code goes here
}
and then call it like this:
onAfterPageLoad: stickem;
1 Comment
James Montagne
That will call the function immediately and not pass a reference to the function. Remove the
().lang-js
onAfterPageLoad: $.stickem