javascript - 设置自定义 anchor

标签 javascript html css

有没有办法在实际 HTML 标记之外的位置自定义设置 anchor ?

我正在使用名为“smoothscroll.js”的简单视差滚动脚本,位于“ http://www.kryogenix.org/code/browser/smoothscroll/smoothscroll.js”。 '

它的工作原理是建立指向 anchor 的链接。 但是,我需要将它们放在标记所在的位置之外。 上方约 200px。

我尝试过使用类和内联的外部 CSS。

EG:

<a name="kids" class="anchor" style="margin-top:-200px;"></a>


<a name="kids" class="anchor" style="margin-top:-200px;"></a>

.anchor { margin-top: -200px; }

有什么建议吗?!

这个问题是这个问题的派生,Anchor point positionings (2-Q分,求助!)

最佳答案

由于 a 不是 block 元素,margin-top 将无法按预期工作。

这是一些修改过的 CSS:

.anchor {
  display: block;
  position: relative; /* relative to the parent container, needed for top/left positioning*/
  top: -200px;
}

关于javascript - 设置自定义 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9380034/

相关文章:

javascript - 在 div 中滚动时如何在 jQuery 中使用 scrollTop?

javascript - 类型错误 : Cannot read property 'open' of undefined modal

html - 在 Angular 中删除元素时如何添加淡入淡出的动画效果?

javascript - 如何使用 javascript 检索复选框的属性值

javascript - 如何在不使用 window.open() 的情况下在 TaskPane 应用程序中下载文件?

javascript - ng-click 在嵌套的 ng-click 中触发了两次

javascript - backbone.js - 渲染 View

javascript - 使用 jQuery 创建 Messenger 应用程序(失败)

css - 仅当元素不是 tfoot 元素时才显示边框

html - 当设置到位置 "fixed"时,Leftnav 缩小宽度