简体   繁体   English

Javascript:具有可滚动的固定位置元素

[英]Javascript: having a scrollable fixed position element

I'm trying to achieve the following: 我正在努力实现以下目标:
I have a pop-in menu docked to the left side of the screen. 我有一个弹出菜单停靠在屏幕的左侧。
The menu has only a small tab visible. 菜单上只有一个小的标签可见。 Upon hover - it pops to accommodate its content. 悬停时-它会弹出以容纳其内容。
The problem is, my pages are sometimes a few screens in height. 问题是,我的页面有时高几个屏幕。 And sometime, so is my menu. 有时候,我的菜单也是如此。
I wish to be able to dock my menu to a fixed position (so the tab is always visible), and have the menu scrollable, without the ugly scrollbars. 我希望能够将菜单停靠在固定位置(因此该选项卡始终可见),并使菜单可滚动,而没有难看的滚动条。

How could this be achieved? 如何做到这一点?

Add to your css: 添加到您的CSS:

html,body { height: 100%; }

#menu { height: 100%; overflow: auto; position: absolute; top: 0px; }

Make sure the #menu is a direct child of body. 确保#menu是身体的直接子代。

If this doesn't work, give me a link to a demo, or make one in http://jsfiddle.net/ 如果这样做不起作用,请给我一个演示链接,或在http://jsfiddle.net/中创建一个演示

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

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