如何在JavaScript中滚动到li的最后一个元素?

时间:2017-04-03 06:28:30

标签: javascript angularjs

这是我的代码。我需要帮助才能滚动到JavaScript中列表的最后一个元素。

<ul class="messages" id="chatBox">
  <!-- ngRepeat: message in message -->
  <li ng-repeat="message in message" class="server">
    <div>
      <p class="usrname ng-binding"></p>
      <p class="dataMessage ng-binding">you have connected to angularjs</p>
    </div>
  </li>
  <!-- end ngRepeat: message in message -->
  <li ng-repeat="message in message" class="mymsg">
    <div>
      <p class="usrname ng-binding">ketan</p>
      <p class="dataMessage ng-binding">xcxz</p>
    </div>
  </li>
  <!-- end ngRepeat: message in message -->
  <li ng-repeat="message in message" class="mymsg">
    <div>
      <p class="usrname ng-binding">ketan</p>
      <p class="dataMessage ng-binding">czxc</p>
    </div>
  </li>
  <!-- end ngRepeat: message in message -->
  <li ng-repeat="message in message" class="mymsg">
    <div>
      <p class="usrname ng-binding">ketan</p>
      <p class="dataMessage ng-binding">czxc</p>
    </div>
  </li>
  <!-- end ngRepeat: message in message -->
  <li ng-repeat="message in message" class="mymsg">
    <div>
      <p class="usrname ng-binding">ketan</p>
      <p class="dataMessage ng-binding">cxz</p>
    </div>
  </li>
  <!-- end ngRepeat: message in message -->
  <li ng-repeat="message in message" class="mymsg">
    <div>
      <p class="usrname ng-binding">ketan</p>
      <p class="dataMessage ng-binding">cxzczx</p>
    </div>
  </li>
  <!-- end ngRepeat: message in message -->
</ul>

1 个答案:

答案 0 :(得分:0)

尝试使用scrollIntoView()方法滚动到最后一个元素或您想要的任何元素。

$(选择器).scrollIntoView();