jquery datatables scroll to top when pages clicked from bottom

后端 未结 7 483
余生分开走
余生分开走 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:55

    None of the above answers worked for me. Here's my solution.

    $("#divContainingTheDataTable").click(function(event){
        if ($(event.target).hasClass("paginate_button")) {
            $('html, body').animate({
                 scrollTop: $("#divContainingTheDataTable").offset().top
            }, 200);
        }
    });
    

    I tried targetting .paginate_button but it never seemed to fire. My approach checks the div containing the datatable, if you click on the pagination buttons, the page scrolls up to the top of the container.

提交回复
热议问题