当滚动到达页面末尾时,我一直在努力向页面添加更多内容。
问题是 JavaScript 无法处理通过 ajax 加载的内容
下面是一个简单的代码:
HTML:
<div class="ajax_load_wrapper">
<div id="title_191">
<div id="title_172">
<div id="title_171">
<div id="title_105">
<div id="title_95">
<!-- new divs load here on which jQuery events don't work -->
</div>
<div id="load_more_vbz" style="display: none;">
<a href="somelink">loading...</a>
</div>
jQuery:
(function ($) {
$(window).on('scroll',function(){
if (($(window).scrollTop() == $(document).height() - $(window).height() )){
load_mode_content();
}
});
//loads more content
function load_mode_content(){
var link = $('#load_more_vbz a').attr('href');
$('#load_more_vbz').show(); //show the loading image
$.get(link).done( function(data){
$('.ajax_load_wrapper').append(data); //appends new data
$('#load_more_vbz').hide();
});
return false;
}
})(jQuery);