简体   繁体   English

jquery菜单栏漂浮顶部

[英]jquery menu bar floating top

I'm trying to make a menu bar float constantly at the top of the browser, so when they scroll down the page the menu bar remains at the top. 我正在尝试使菜单栏不断浮动在浏览器的顶部,因此当它们向下滚动页面时,菜单栏仍然位于顶部。

How could I go about doing this? 我怎么能这样做?

Regards, 问候,

The CSS tag position: fixed; CSS标签position: fixed; will make it stay in the same position on the screen, even if scrolling. 即使滚动,它也会使它保持在屏幕上的相同位置。 Use that and then position it with top/right/bottom/left as shown below. 使用它,然后将其top/right/bottom/lefttop/right/bottom/left ,如下所示。 z-index will affect how high it is 'stacked'. z-index将影响“堆叠”的高度。 That is, an element with a z-index of 1 will be beneath an element of a z-index of 100. 也就是说, z-index为1的元素将位于z-index为100的元素之下。

div.float {
    position: fixed;
    top: 10px;
    left: 25px;
    z-index: 9001;
}

jsfiddle.net was down earlier, but it's back up. jsfiddle.net早些时候倒闭了,但它已经恢复了。 Here's an example of a floating menu that is static until you scroll to a certain point: http://jsfiddle.net/2rhrc/ 这是一个浮动菜单的示例,在您滚动到某个点之前是静态的: http//jsfiddle.net/2rhrc/

You can do this using the CSS position property. 您可以使用CSS position属性执行此操作。 For example: 例如:

#menu {
  height: 50px;
  left: 0;
  position:fixed;
  top: 0;
}

References: 参考文献:

The first place I noticed this used effectively is on the Perldoc site. 我注意到有效使用的第一个地方是在Perldoc网站上。 If you have to scroll, the #content_header element uses a combination of CSS and JS to keep the element visible on the page. 如果必须滚动,则#content_header元素使用CSS和JS的组合来保持元素在页面上可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM