1

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
1
  • Remove the braces onAfterPageLoad: $.stickem Commented Jun 2, 2013 at 23:49

2 Answers 2

7

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
Sign up to request clarification or add additional context in comments.

8 Comments

that did it, thank you. another question though, would i be able to add more to that paticular function.
Of course. =] Anything inside the function callback will execute once the onAfterPageLoad event fires.
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'); }
@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.
thank you, just tried it but got no luck. but thanks for your help!
|
5

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;
BenMorel
37.1k53 gold badges208 silver badges339 bronze badges
answered Jun 2, 2013 at 23:49

1 Comment

That will call the function immediately and not pass a reference to the function. Remove the ().

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.