简体   繁体   English

单击分页页面时向上滚动

[英]Scroll up when you click on the pagination page

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/ .有一个帖子页面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从 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); } }); } });

I cannot see your HTML, so assuming that #more-news is where you would want to dock to我看不到你的 HTML,所以假设#more-news是你想要停靠的地方

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 .这里有更多选项 - https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView平滑行为仅限于某些浏览器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM