jquery datatables scroll to top when pages clicked from bottom

后端 未结 7 615
余生分开走
余生分开走 2021-01-02 17:13

I am using a jQuery datatable with bottom pagination. When the pages are clicked from bottom , I want it to scroll it to top, so users do not have to manually do that for lo

7条回答
  •  渐次进展
    2021-01-02 17:57

    This worked out for me.

    $(document).ready(function() {
        var oldStart = 0;
        $('#example').dataTable({
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "fnDrawCallback": function (o) {
                if ( o._iDisplayStart != oldStart ) {
                    var targetOffset = $('#example').offset().top;
                    $('html,body').animate({scrollTop: targetOffset}, 500);
                    oldStart = o._iDisplayStart;
                }
            }
        });
    } );
    

提交回复
热议问题