javascript - 在数据表中垂直滚动动画

标签 javascript jquery html css datatables

我想使用数据表显示所有数据。但我希望这些数据每 3 秒自动(动画)滚动每一行

这是我的代码,这是我的 jsfiddle

我想在大屏幕上显示数据。

<html>
<head>
      <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
      <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
      <script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
      <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
      <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.1/css/jquery.dataTables.css">
      <script type="text/javascript" src="//cdn.datatables.net/1.10.1/js/jquery.dataTables.min.js"></script>
      <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/responsive/1.0.0/css/dataTables.responsive.css">
      <script type="text/javascript" src="//cdn.datatables.net/responsive/1.0.0/js/dataTables.responsive.js"></script>
      <style type="text/css">
        table th:nth-child(3), td:nth-child(3) {
        display: none;
        }
      </style>
      <title>jQuery Datatables responsive example</title>
      <script type='text/javascript'>
        $(window).load(function(){
            $(document).ready(function() {
            $('#example').DataTable({
            "scrollX": true,
            "animate": true,
            "bLengthChange": false,
            "bFilter": false,
            "bInfo" : false,
            "paging":   false
            });
            });
        });
    </script>
</head>
<body>
  <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>

        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
        <tbody>
            <tr>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
            <tr>
                <td>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</td>
            </tr>
            <tr>
                <td>Ashton Cox</td>
                <td>Junior Technical Author</td>
                <td>San Francisco</td>
                <td>66</td>
                <td>2009/01/12</td>
                <td>$86,000</td>
            </tr>
            <tr>
                <td>Cedric Kelly</td>
                <td>Senior Javascript Developer</td>
                <td>Edinburgh</td>
                <td>22</td>
                <td>2012/03/29</td>
                <td>$433,060</td>
            </tr>
        </tbody>
    </table>
</body>

</html>

帮帮我,谢谢

最佳答案

你可以像这样使用delay():

$(document).ready(function() {
    $('#example').DataTable({
        "scrollX": true,
        "animate": true,
        "bLengthChange": false,
        "bFilter": false,
        "bInfo" : false,
        "paging":   false
    });

    $('#example > tbody  > tr').each(function() {
    $('html, body').animate({
        scrollTop: $(this).offset().top
    }, 200).delay(2800);        
    });

} );

fiddle

关于javascript - 在数据表中垂直滚动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42220756/

相关文章:

php - 创建一个动态的单页 Web 应用程序

javascript - 如何将 Woocommerce 与 Piwik 集成

javascript - JQuery ajax 从来没有成功。有什么错误吗?

javascript - 确保我的随机值数组不包含重复值

javascript - Flexslider 箭头有问题,如何解决?

javascript - 如何使用 JavaScript 获取 AJAX 的选择值

JQuery 替换元素带向左滑动效果

jquery - jquery代码中 undefined variable

javascript - 如果在 uib-tabset 中使用,则值不与范围的变量绑定(bind)

javascript - 如何覆盖 `<base target="_blank">`