<!DOCTYPE html><html lang="zh-cn"><head><meta charset="UTF-8"><title>锚点</title></head><body><ul><li><a href="javascript:void(0);" οnclick="naver('A')">锚点A</a></li><li><a href="javascript:void(0);" οnclick="naver('B')">锚点B</a></li><li><a href="javascript:void(0);" οnclick="naver('C')">锚点C</a></li><li><a href="javascript:void(0);" οnclick="naver('D')">锚点D</a></li></ul><p style="background-color: #f60; height: 400px;" id="A">AAA</p><p style="background-color: #f06; height: 400px;" id="B">BBB</p><p style="background-color: #60f; height: 400px;" id="C">CCC</p><p style="background-color: #06f; height: 400px;" id="D">DDD</p><script>//设置锚点function naver(id){var obj = document.getElementById(id);var oPos = obj.offsetTop;return window.scrollTo(0, oPos-36);}</script></body></html>
效果图: