基本上我正在寻找能够在网页上的某个位置显示div
的代码。当你滚动到网站时,当你处于特定的标题时,你会得到某些标题,div需要在导航栏中显示。
div #greybar是在滚动时只需要在某个位置可见的div,整个导航栏是固定的
HTML:
<div class="navbar">
<div class="container">
<div class="logo">
<img src="images/logotekst.png">
</div>
<div id="menubutton"><a onclick="playclip();" href="#homejump">Home</div>
<div id="menubutton"><a onclick="playclip();" href="#aboutjump">About</div>
<div id="menubutton"><a onclick="playclip();" href="#infojump">Info</div>
<div id="menubutton"><a onclick="playclip();" >test</div>
</div>
<div id="greybar"></div>
</div>
CSS:
#greybar {
width: 100%;
height: 5px;
background-color: #A4A4A4;
}
答案 0 :(得分:-1)
如果您使用的是javascript和jQuery,可以查看jQuery函数 hover,show,hide,text。在所有页面的末尾,都有很好的例子。
编辑:您应该使用class="menubutton"
而不是id="menubutton"
。
之后,您可以使用
这样的脚本 <script>
$( "div.menubutton" ).hover(
function() {
$( "#greybar" ).text( $( this ).text());
$( "#greybar" ).show();
}, function() {
$( "#greybar" ).hide();
$( "#greybar" ).text("");
}
);
</script>
编辑2:
添加到greybar类position: fixed;