I have a loop of posts that I use infinite scroll to paginate. I use SimpleModal to call a full post popup of each post but it only works on the posts that are loading initially. Any post called by the infinite scroll just clicks through to the actual post page. Why is that happening?
That's because your SimpleModal function is applied to all posts that exist on the page when the document is loaded.
The infinte scroll thing will fire ajax requests and add new posts (excerpts) on the page, after the document is loaded.
What you need to do is to attach the SimpleModal function on click events registered in the future as well. So if you have something like:
$('.post').click(function(){
// show modal
});
change it to
$('.post').on('click', function(){
// show modal
});
I'm assuming here these scripts are jQuery plugins.
See $.on()
$.on()
only works in jQuery 1.7+. If you have an older version, then use live(): jQuery('a.postpopup').live('click', function...
, or delegate(): jQuery('.container').delegate('a.postpopup', 'click', function...
nice ass 2012-04-07 18:36
$
to the function you bind on document.ready. This way you can safely use $ instead of jQuery
within your function. Also, if the id
variable is not meant to be global, define it first with the var
keyword - nice ass 2012-04-07 18:45