Jquery 使用slimscroll插件滚动顶部

Jquery 使用slimscroll插件滚动顶部,jquery,ajax,Jquery,Ajax,我在我的网页上使用了slimScroll,内容是由AJAX添加的 如果我向下滚动滚动,然后重新加载更多内容(AJAX加载),滚动条本身的位置始终保持与以前相同 我想知道slimScroll是否有任何功能可以在加载新内容后调用以滚动到顶部?自1.0.0版以来,如果需要滚动到顶部,可以使用内置的方法: $(元素).slimScroll({scrollTo:'0'})我认为@rochal描述的滚动选项现在不起作用,因为它似乎没有被使用。相反,请尝试scrollTo或scrollBy 要滚动到顶部: $

我在我的网页上使用了
slimScroll
,内容是由AJAX添加的

如果我向下滚动滚动,然后重新加载更多内容(AJAX加载),滚动条本身的位置始终保持与以前相同


我想知道
slimScroll
是否有任何功能可以在加载新内容后调用以滚动到顶部?

自1.0.0版以来,如果需要滚动到顶部,可以使用内置的方法:


$(元素).slimScroll({scrollTo:'0'})

我认为@rochal描述的
滚动
选项现在不起作用,因为它似乎没有被使用。相反,请尝试
scrollTo
scrollBy

要滚动到顶部:

$('#elem_id').slimScroll({ scrollTo : '0px' });
相反,如果要滚动到底部,则应执行以下操作:

var scrollTo_val = $('#elem_id').prop('scrollHeight') + 'px';
$('#elem_id').slimScroll({ scrollTo : scrollTo_val });

或者,您可以使用javascript来解决此问题

document.getElementById("element-id").scrollTop = document.getElementById("element-id").scrollHeight;
element id
是内容区域的
id
(通常是它的
div


当新内容附加到您的
div

时执行此代码。此代码已为我运行

var scrollTo_int = $('#elem_id').prop('scrollHeight') + 'px';
$('#elem_id').slimScroll({scrollTo : scrollTo_int });

这将在底部位置使用滚动条,同时在分区底部使用内容。

对于我来说,作者@rochal建议的答案不起作用,也不作为slimScroll配置参数:都滚动内容,但不滚动手柄,其中一个甚至会破坏我的容器高度

相反,这对我起了作用:

// let's assume the plugin was initialized with this class name present:
$('.slim-scroll').slimScroll(config);

// then this is the solution.
$('.slimScrollDiv.inQuestion').find('.slimScrollBar').css({ top: 0 }).end().find('.slim-scroll').get(0).scrollTop = 0;

// -----------------------------
// once more, with explanations:
$('.slimScrollDiv.inQuestion')        // this is the ‹div› wrapped around our .slim-scroll element by the plugin. It always has the 'slimScrollDiv' class name.

  .find('.slimScrollBar')             // first address the handle. The order is important because we're going to break the chain at the end.
    .css({ top: 0 })                  // 'scroll' it.
  .end()                              // stay in the jQuery chain; go back to the last jQuery collection before find().

  .find('.slim-scroll')               // address the content.
    .get(0)                           // leave jQuery terrain, get the DOM element.
      .scrollTop = 0                  // scroll it.
;

感谢Rochal提供的优秀插件,这确实是我在互联网上能找到的最好的插件之一,但这种方式似乎无法解决我的问题。在我使用ajaxI重新加载内容后,滚动条仍然保持其位置,但存在完全相同的问题。内容会滚动到顶部,但滚动条仍保持在原来的位置。有没有人对此有其他想法?这对底部的卷轴很有用。我爱你。我真的喜欢。你刚才帮了我很多忙:)