确保点击加载更多不会导致用户滚动到顶部

Ensure click of load more does not cause user to scroll to top

我在 Drupal 站点中加载更多时遇到问题。示例 link:https://www.nova969.com.au/tag/news

如果用户在该页面中按下“加载更多”,您会注意到用户被带到了顶部。加载更多内容。但是,用户也会滚动到顶部。我希望用户停留在点击加载更多的位置

加载更多是通过视图加载更多 (https://www.drupal.org/project/views_load_more) 完成的,如下所示

<ul class="pager pager-load-more">
<li class="pager-next first last">
<a href="/tag/news?page=1">Load more</a>
</li>
</ul>

非常感谢任何帮助。

提前致谢。

更新:

我试过如下

/* Views Ajax Content Load Autoscroll Feature Disabled */
jQuery(document).ready(function(){
        //On page load
        jQuery('.pager-item a.views-ajax-scroll-processed').click(function(){
        jQuery('body, html').stop();
    });
        //Again after ajax request is completed
        jQuery(document).ajaxComplete(function(){
        jQuery('.pager-item a.views-ajax-scroll-processed').click(function(){
            jQuery('body, html').stop();
        });
    });
});

那没有用。在下面尝试过:

(function($){

      if (Drupal.ajax)
         Drupal.ajax.prototype.commands.viewsScrollTop = null;

})(jQuery);

那没有用。试过下面的行被注释掉了。那也失败了

//$(scrollTarget).animate({scrollTop: (offset.top - 10)}, 500);

请帮忙?

我检查了您页面上的脚本,您似乎有一个自定义行为,无论发生什么情况都会触发滚动到顶部。

Views load-more 脚本对每个新的附加内容应用 Drupal.attachBehaviors()。在您的情况下,当附加新项目时,sidebar 行为会重新附加并重新初始化:

Drupal.behaviors.sidebar = {
  attach: function (context, settings) {/*...*/},
  init: function () {
    $(window).scrollTop(1); // <- your issue here. 
    // ...
  }
};

有趣的是,作者在同一行发表了评论,解释说这是解决另一个问题的方法,并建议打败他...所以你会得到一个 new/old 错误解决这个。可怕的级联错误修复错误...;)