代码之家  ›  专栏  ›  技术社区  ›  T.T.T.

如何自动滚动到特定的表行?

  •  6
  • T.T.T.  · 技术社区  · 15 年前

    我有一个带有页眉的html页面,一个包含100个项目和一个页脚的表。

    但是,如果高亮显示的行是第75行,则用户必须向下滚动才能找到它。

    如何自动滚动到该行?

    我确实看到了 scrollTo() 但它只需要轴心点。

    有什么建议吗?

    谢谢。

    (在C、html、css和javascript/jquery中使用cgi)

    3 回复  |  直到 14 年前
        1
  •  9
  •   Pointy    15 年前

    scrollIntoView() . (直接在DOM元素上)

    请注意,在某些布局情况下,滚动页面上的某些内容可能会导致IE6和ie7决定需要滚动随机的其他内容。

        2
  •  3
  •   sushil bharwani    15 年前

    试试这个:

    <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)">
    
    
        3
  •  0
  •   Community Mohan Dere    9 年前

    我想你可以这样做:

    随便你用这条线,

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

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

    这对我来说很管用,但却没有起锚。

    再次检查是否在html中使用书签

    编辑时间: 支票: JavaScript - Jump to anchor