javascript - 在滚动动画中将锚链接移高一点
问题描述
我为自己的网站使用锚链接。并且有滚动动画。但是因为标题是粘性的,所以它隐藏了标题。所以我想去锚链接去的更高的地方。可能吗?
HTML:
<li><a href="#example">Example</a></li>
JS:
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
解决方案
推荐阅读
- c - 使用 open("/dev/fd/n", mode) 重新打开现有文件描述符
- python - 如何用多行查找/替换python语句并保持正确的缩进?
- python - !unzip 在 jupyter 单元格中未被识别为命令
- json - 在 Dart 中使用唯一键解析 JSON 对象
- c++ - 使用堆栈的 NQueens 问题,代码给出不正确的输出
- css - 如何在 React Native 中使用 css position absolute 和 flex end
- python - 无法将已安装的 python 库 Yellowbrick 导入到 jupyter notebook
- amazon-web-services - 如何在 AWS EKS 设置中的 ksonnet 初始化步骤中解决“错误未找到 Major.Minor.Patch 元素”
- amazon-web-services - 反复出现的警告 - 无法清理 KCL 2.3 上的租约
- python - 如何修剪列表的特定元素?