开发者

Keep page position when update an DOM element using jQuery

开发者 https://www.devze.com 2023-03-15 16:23 出处:网络
I have a long table with many rows and have to scroll down to see all of them. When I update the last row, the browser automatically scroll to the top of the page. How can I fix it开发者_JAVA百科?

I have a long table with many rows and have to scroll down to see all of them. When I update the last row, the browser automatically scroll to the top of the page. How can I fix it开发者_JAVA百科?

<table>
   .....
   <tr>
       <td id='row_xxx'>

       </td>
   </tr>
   .....
</table>

and script

$("row_xxx").html("abc abc ab");


I'll guess you could use the window.scrollto() functionality.

http://www.w3schools.com/jsref/met_win_scrollto.asp

Or jquery scrolltop

$("#row_xxx").scrollTop($("#row_xxx").attr("scrollHeight"));


You can use scrillHeight attribute.

$("#myTable").attr(
{ 
    scrollTop: $("#myTable").attr("scrollHeight") 
});
0

精彩评论

暂无评论...
验证码 换一张
取 消