繁体   English   中英

如何使用jQuery滚动底部?

[英]How to Scroll Bottom using Jquery?

实际上我正在使用以下代码在顶部滚动

 var container = $('#items_suggession_right'), scrollTo = $(".selected");
         container.animate({scrollTop: scrollTo.offset().top - container.offset().top +
                       container.scrollTop()}, 0); 

但我不能滚动设置在底部。 请帮助我使用jQuery设置底部滚动

您可以使用

var time = 0; // in milliseconds
$("html, body").animate({ scrollTop: $(document).height() }, time);.

您可以增加时间值以提供更平滑,更生动的滚动到底部。

输入以下代码以滚动到页面底部。

container.animate({ scrollTop: $(document).height() }, 0);
$(document).on("click","#bottom",function() {
  var window_height = $(window).height();
    var document_height = $(document).height();
    $('html,body').animate({ scrollTop: window_height + document_height },1000);
});

希望能帮助到你!

$(document).ready(function() {

    $('#buttonID').click(function(){
        $('html, body').animate({scrollTop:$(document).height()}, 'slow');
        return false;
    });

});

只需使用此代码部分。

您可以使用 :

$('html').animate({ scrollTop: $(document).height() }, 1000);

jsfiddle代码已更新,可滚动到底部

  $(document).ready(function() { $('html,body').animate({ scrollTop: $('.testwrap').height() }, 800); }); 
 .testwrap{ width: 500px; height: 1000px; border: 2px dotted #c00; } 
 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script> </head> <body> <div class="testwrap"></div> </body> </html> 

暂无
暂无

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

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