A
A
Andrey2018-01-29 08:57:23
JavaScript
Andrey, 2018-01-29 08:57:23

How to make the back button return to the previous screen with infinite scroll?

Implemented infinite scrolling of posts for this guide . Here is the main code of the script to load posts endlessly on page scroll

jQuery(function($){
  $(window).scroll(function(){
    var bottomOffset = 2000; // отступ от нижней границы сайта, до которого должен доскроллить пользователь, чтобы подгрузились новые посты
    var data = {
      'action': 'loadmore',
      'query': true_posts,
      'page' : current_page
    };
    if( $(document).scrollTop() > ($(document).height() - bottomOffset) && !$('body').hasClass('loading')){
      $.ajax({
        url:ajaxurl,
        data:data,
        type:'POST',
        beforeSend: function( xhr){
          $('body').addClass('loading');
        },
        success:function(data){
          if( data ) { 
            $('#true_loadmore').before(data);
            $('body').removeClass('loading');
            current_page++;
          }
        }
      });
    }
  });
});

Everything is fine, but the problem is that if you scroll to the third or fourth screen, then follow the link to some post, and then press back, it returns to the end of the first screen.

Tell me what needs to be added to the above code so that the return occurs to the place where the link was clicked.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question