知识学堂 > 课程 > jquery 让滚动条处于div底部

jquery 让滚动条处于div底部

发布日期:2023/3/21 来源:聚恒【返回】

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>jQuery Scroller</title>
  6. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  7. </head>
  8. <body>
  9. <div id="myDiv" style="width: 500px; height: 100px; overflow: auto; border: 1px solid black;"></div>
  10. <input type="text" id="myTextInput" />
  11. <input type="button" value="Send" id="postButton" />
  12. <div id="info"/>
  13. <script type="text/javascript">
  14. $(document).ready(function(){
  15. $('#postButton').click(function(){
  16. $('#myDiv').append($('#myTextInput').val() + '<br/>');
  17. $('#myTextInput').val('');
  18. $("#myDiv").animate({ scrollTop: $("#myDiv")[0].scrollHeight - $('#myDiv').height() }, 3000);
  19. });
  20. });
  21. </script>
  22. </body>
  23. </html>