页面内锚点定位及跳转方法总结

最简单的方法是锚点用<a>标签,在href属性中写入DIV的id。如下:

<!DOCTYPE  html>
<html>
<head>
    <style>
        div {
            height: 800px;
            400px;
            border: 2px solid black;
        }
        h2 {
            position: fixed;
            margin:50px  500px;
        }
    </style>
</head>
<body>
    <h2>
        <a href="#div1">to div1</a>
        <a href="#div2">to div2</a>
        <a href="#div3">to div3</a>
    </h2>
    <div id="div1">div1</div>
    <div id="div2">div2</div>
    <div id="div3">div3</div>
</body>
</html>

    

 

  第2种方式是在js事件中通过window.location.hash="divId"跳转
 
  

原文地址:https://www.cnblogs.com/cowboybusy/p/9041640.html