Ok guys. I have a link with class name “more_updates”. I want the load more link to be triggered automatically everytime the user reach 80% of the page.
I’m listing 50 products. Each row contains 5 products with images. At the bottom i have load more link. If the user reach 7th or 8th row then the load more link should be triggered automatically. This is the code i’m using. But it loading more products.
Please tell me whats wrong in this code. Thanks
<!-- language: lang-js -->
$(window).scroll(function(){
if ($(window).scrollTop() >= ($(document).height() / 2) - $(window).height()){
if (!flag) {
// if is not loading data, start the call
$('.more_updates').click(); // to invoke the click event of loading updates
}
}
});
I think you are triggering the click event in wrong way (because in your case it isn’t triggered by user but by scroll method). Change
$('.more_updates').click();to$('.more_updates').trigger("click");read more here
EDIT/UPDATE:
Stop event bubbling on your click event:
read more here
Also unbind/die click event of
.show_morewhen there no results condition is met:read more here