0

Can you please tell us how to make a scroll up when you click on the pagination page? There is a page of posts https://tvoidv.ru/culture/.

When you click on "Show more" (in itself) the page remains in place, but you need it to hide up or somehow it seems that the update has occurred. How can this be done?

Post loading code from json

$(document).on('click', '#more-news', function(e) {
    e.preventDefault();
    var _url = $(this).attr('data-url');
    send = false; //убираем шумы
    if (_url && !send) {
        $.ajax({ 
            url: _url,
            type: 'GET',
            dataType: 'json',
            beforeSend: function() {
                // включение прелоудера
                send = false;
            },
            complete: function() {
                // отключение прелоудера
            }, 
            success: function(obj) { 
                send = true;
                
                $('#more-news').remove(); //удаляем текущю кнопку
                $("#get_news").append(obj['html'])//добавляе  готвую разметку

                if('show_more' == true){
                    $('#more-news').show();
                } else {
                    $('#more-news').hide();
                } //добавляем кнопку если пришел флаг
            },
            error: function(xhr, ajaxOptions, thrownError) {
                console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText + "\r\n" + xhr);
            }
        });
    }
});
mo link
  • 83
  • 5
  • Does this help? https://stackoverflow.com/questions/1144805/scroll-to-the-top-of-the-page-using-javascript – Anis R. Aug 28 '20 at 14:29

1 Answers1

1

I cannot see your HTML, so assuming that #more-news is where you would want to dock to

Add this to the success block after the element is visible

var element = $('#more-news').get(0)
element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});

More options here - https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView Smooth behavior is limited to certain browsers.

Ramakay
  • 2,919
  • 1
  • 5
  • 21
  • Thank you for the solution, what you need, but just how do you make sure that the offset is not to the object that already exists, but to the one that appears? You mean how to add an upward indent? – mo link Aug 28 '20 at 15:21