1

我有一个分组在表格中的项目列表,比如说 30,我想要做的是以下内容:

  • 从底部到顶部自动垂直滚动,无需按钮单击或鼠标事件

这是我使用的代码:

        function scrolling(){
            $('#scrollup table').animate(
            { 
                top: '-=10'
            },
            1000,
            'linear',
            function(){

                      if($('#scrollup table  tr:last').offset().top<0){
                     $('#scrollup table  tr:first').remove();   
                    $('#scrollup table  tr:last').after('<tr>'+$('#scrollup table  tr:first').html()+'</tr>');
                }
            }
        );
        }
        $(document).ready(function(){
            setInterval('scrolling()',200)
        });

你能告诉我我错过了什么或问题出在哪里吗?

4

1 回答 1

2

看看这段代码:

  function scrolling(){
        var table = $('#scrollup table');
        table.animate(
        { 
            top: '-=5'
        },
        200,
        'linear',
        function(){                
            if($('#scrollup table tr:first').height() <= -parseFloat(table.css("top"))){
                 $('#scrollup table').css("top", 0);
                 $('#scrollup table  tr:last').after($('#scrollup table tr:first').detach());
            }
        }
    );
    }
    $(document).ready(function(){
        setInterval('scrolling()',200)
    });​

它工作正常(演示),但只有当所有行都具有相同的高度时才会好。我正在尝试找到适用于不同高度行的更好解决方案。基本上,您的代码的问题是您总是向上移动表格(使用.animate),但删除第一行并将其添加到表格的末尾(因此表格高度不会增加)

更新 代码以使用差异高度线。演示

于 2012-09-28T17:10:30.767 回答