最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I auto-scroll to a specific table row? - Stack Overflow

programmeradmin3浏览0评论

I have an html page with a header, a table containing 100 items and a footer.

When there is a search, I highlight the row containing the data.

However, if the highlighted row is row 75, the user has to scroll down to find it.

How can I automatically scroll to that row?

I did see scrollTo() but see it only takes axis points.

Any suggestions?

Thanks.

(Using cgi in C, html, css and javascript/jquery)

I have an html page with a header, a table containing 100 items and a footer.

When there is a search, I highlight the row containing the data.

However, if the highlighted row is row 75, the user has to scroll down to find it.

How can I automatically scroll to that row?

I did see scrollTo() but see it only takes axis points.

Any suggestions?

Thanks.

(Using cgi in C, html, css and javascript/jquery)

Share Improve this question edited Nov 21, 2011 at 13:44 nikow 21.6k7 gold badges53 silver badges71 bronze badges asked Sep 23, 2010 at 18:03 T.T.T.T.T.T. 34.6k47 gold badges134 silver badges172 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 9

You should be able to use scrollIntoView(). (It's on the DOM elements directly.)

Be aware that there are some layout situations where scrolling something on the page can cause IE6 and 7 to decide that random other stuff needs to be scrolled too.

try this:

<script>
function ScrollToElement(theElement){

  var selectedPosX = 0;
  var selectedPosY = 0;

  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }

 window.scrollTo(selectedPosX,selectedPosY);

}
</script>

<body onload="ScrollToElement(document.formName.elementName)">

I think you can do something like this:

Use this line where ever you like,

<a id="bookmark"></a>

and when you start your page, call it like this:

http://mypage./setting.php#bookmark

That worked for me without showing the anchor.

Check again for using bookmark in html

EDITED: Check: JavaScript - Jump to anchor

发布评论

评论列表(0)

  1. 暂无评论