[removed] Scroll to nth row in a table?

前端 未结 5 920
暖寄归人
暖寄归人 2020-12-30 05:21

Using either pure Javascript or jQuery, how do I scroll the page so that the nth row in a table is centered on the page?

Some examples I\'ve seen that have this sort

5条回答
  •  不知归路
    2020-12-30 06:19

    Give this a shot:

    /*pseudo-code*/
    $("td.class").bind("click", function() {
    
        var y = $(this).position().top,
            h = $(window).height();
    
        if(y > h/2) {
            $("body").animate({
                scrollTop: y - h/2
            }, 2000);
        };
    });
    

提交回复
热议问题