小编lin*_*lus的帖子

jQuery Custom Content Scroller不会滚动到底部

我使用mCustomScrollbar作为页面上的元素,有时会重新加载.这是一个消息视图,当用户点击另一个对话时,会加载此对话的消息.但是,当我想在加载它之后滚动到底部,因为最新的消息在底部,它滚动到底部但是在底部以上几个像素("一些"可以在10到200px之间随机).

以下是一个简化示例:

// code to load another conversation
$(".conversations .conversation").click(function (e) {
    var $this = $(this);
    $.ajax({
        url: W.sprintf('/messages/%s/fetch', $this.attr("data-cid")),
        dataType: 'html'
    }).done(function(data) {
        $('.main_pane.messages').html(data);
        // a function call to set the hight of .main_list.messages goes here
        $(".main_list.messages").mCustomScrollbar(W.scroll_prefs);
        $(".main_list.messages").mCustomScrollbar("scrollTo", "bottom");
        // also tried adding an element at bottom and scrolling to this
        // and scrollTo Number.MAX_VALUE
        // also tried putting the two mCustomScrollbar lines both into
        // setTimeout()
    });
});
Run Code Online (Sandbox Code Playgroud)
<!-- this is what gets loaded -->
#conversation
  .head
    -# …
Run Code Online (Sandbox Code Playgroud)

jquery scroll jquery-plugins mcustomscrollbar

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

jquery ×1

jquery-plugins ×1

mcustomscrollbar ×1

scroll ×1