javascript jQuery Perfect Scroll - 将滚动条设置到容器底部

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19418087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 15:30:59  来源:igfitidea点击:

jQuery Perfect Scroll - Set Scrollbar to the Bottom of the Container

javascriptjqueryjquery-plugins

提问by Jason Biondo

I have just installed perfect scroll, the jQuery plugin, and it works great but I can't find a parameter to start the content at the bottom of my div. I want to have to scroll up on page load, not to have to scroll down.

我刚刚安装了完美的滚动,jQuery 插件,它工作得很好,但我在我的 div 底部找不到启动内容的参数。我想在页面加载时向上滚动,而不是向下滚动。

Normally with jQuery I would just do:

通常使用 jQuery 我只会做:

$(nav_message_list).prop({ scrollTop: $(nav_message_list).prop("scrollHeight")});

But that seems to have no effect.

但这似乎没有效果。

Current code:

当前代码:

$(".chat_person").click(function ()
                         {
                          if (!$(".chat_content_wrap").is(":visible"))
                           {  
                            $(".chat_content_wrap").fadeIn(300, function ()   
                                                                 {
                                                                  $('#message_list').perfectScrollbar('update');
                                                                  $(nav_message_list).prop({ scrollTop: $(nav_message_list).prop("scrollHeight")});
                                                                 });
                           }
                          });

$("#message_list").perfectScrollbar();

回答by Travis Petrie

I haven't used the plugin before but based on the docs at https://github.com/noraesae/perfect-scrollbar

我之前没有使用过该插件,但基于https://github.com/noraesae/perfect-scrollbar上的文档

The code you should need is:

您应该需要的代码是:

$("#message_list").scrollTop( $( "#message_list" ).prop( "scrollHeight" ) );
$("#message_list").perfectScrollbar('update');

The $ selectors may be wrong since I can't see you HTML code.

$ 选择器可能是错误的,因为我看不到您的 HTML 代码。

回答by Tony Kuttan

Scrooltop

滑盖

paste below JavaScript code just before </head>code.

在代码之前粘贴在 JavaScript 代码下方</head>

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

paste below JavaScript code just <body>code.

粘贴下面的 JavaScript 代码只是 <body>代码。

    <div class="scrool">
<script type="text/javascript" src="http://static.tumblr.com/ikeq9mi/DfYl6o46t/scrolltotop.min.js"></script>
    <a href="javascript:;" id="scrollToTop" rel="nofollow" title="Go to Top"><img src="http://static.tumblr.com/cqpvki8/7yWlh05zn/seta.png" title="Go to Top" alt="Go to Top"/></a>
</div>

Now on the Customize page, Go and Hit the button “Edit HTML” and add below css codes just before

现在在自定义页面上,点击“编辑 HTML”按钮并在之前添加以下 css 代码

#scrollToTop:link, 
#scrollToTop:visited {
  display: none;
  position: fixed;
  top: 20px;
  right: 20px;
}

For reference http://www.tumblings.net/post/38379026809/scrolltotopbuttoncodeUse this code

供参考http://www.tumblings.net/post/38379026809/scrolltotopbuttoncode使用此代码