javascript - 在 header 中显示 id 属性

标签 javascript jquery html css

我有这个页面:

http://i.stack.imgur.com/AfPWJ.jpg

http://jsfiddle.net/fLGQJ/

我想在滚动时捕获我所在的 div。在标题中通过在标题中显示 id 属性

类似于:

var a =   // the topmost div
( $(document).scrollTop() > $(a).position().top) {    
    console.log($(a).attr('id'))
}

我希望在标题中显示 div 的 id 属性

我可以在没有插件的情况下实现吗,只需 2-3 行?甚至一个插件,如果有的话

这是html示例

  <div class="vs" id="Genesis 1:1">
    &nbsp;1 In the <a href="GenesisRef.html#Genesis%201">a</a>beginning <a href="GenesisRef.html#Genesis%202">b</a>God created the heaven and the earth.
  </div>

  <div class="vs" id="Genesis 1:2">
    &nbsp;2 And the earth was without form, and void; and darkness was upon the face of the deep. <a href="GenesisRef.html#Genesis%203">c</a>And the Spirit of God moved upon the face of the waters.
  </div>

  <div class="vs" id="Genesis 1:3">
    &nbsp;3 <a href="GenesisRef.html#Genesis%204">d</a>And God said, <a href="GenesisRef.html#Genesis%205">e</a>Let there be light: and there was light.
  </div>

  <div class="vs" id="Genesis 1:4">
    &nbsp;4 And God saw the light, that it was good: and God divided the light from the darkness.
  </div>

  <div class="vs" id="Genesis 1:5">
    &nbsp;5 And God called the light <a href="GenesisRef.html#Genesis%206">f</a>Day, and the darkness he called Night. And the evening and the morning were the first day.
  </div>

  <div class="vs" id="Genesis 1:6">

    &nbsp;6 And God said, <a href="GenesisRef.html#Genesis%207">g</a>Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.
  </div>

  <div class="vs" id="Genesis 1:7">
    &nbsp;7 And God made the firmament, <a href="GenesisRef.html#Genesis%208">h</a>and divided the waters which were under the firmament from the waters which were <a href="GenesisRef.html#Genesis%209">i</a>above the firmament: and it was so.
  </div>

  <div class="vs" id="Genesis 1:8">

    &nbsp;8 And God called the firmament Heaven. And the evening and the morning were the second day.
  </div>

  <div class="vs" id="Genesis 1:9">
    &nbsp;9 And God said, <a href="GenesisRef.html#Genesis%2010">j</a>Let the waters under the heaven be gathered together unto one place, and let the dry land appear: and it was so.
  </div>

  <div class="vs" id="Genesis 1:10">
    &nbsp;10 And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good.
  </div>

例如,如果 div 5 位于顶部,则应显示 Genesis 1:5

最佳答案

我想你可能正在寻找

a.appendTo("#Header-Div");

这将在您的其他编码之后进行。只需将 header-div 替换为您希望它进入的框的任何 id。

关于javascript - 在 header 中显示 id 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20299456/

相关文章:

javascript - 当管理员单击注销按钮时,从管理屏幕注销任何用户

javascript - 更改嵌套子菜单 CSS 的功能不起作用(jQuery)

javascript - Jquery:模糊功能不适用于 Div 标签

javascript - 我正在使用 Jquery 来定位我的 Logo 的 "src"属性,

javascript - 根据填充的其他输入动态生成选择输入 'required'

javascript - 如何将 jQuery 的 .html 方法指向外部 HTML 包装?

javascript - Highcharts (javascript) 奇怪的工件(bug?),带有简单的图形

javascript - 将轴标签与刻度下的类型类别对齐

javascript - 无限 Ajax 滚动 : Only loads one page, 然后停止工作

javascript - 如何在提交后重置表单