0

天哪,我在单页网站的屏幕顶部固定了浮动菜单。当我单击菜单项时,页面会慢慢向下滚动到使用 jquery 的相应部分。我在屏幕顶部有固定菜单的代码:

<style>
.fixed_elements{ position:fixed; top:100px; }
        #top-floating-bar{ background: none repeat scroll 0 0 #2D2D2D; height: 35px; position: fixed; top: 0; width: 100%; z-index: 100; }
        ul{ padding: 0; margin: 0; }
        .fixed-bar-buttons{ float: left;color: #fff; }
        .fixed-bar-buttons ul { height: 25px; padding-right: 10px; }
        .fixed-bar-buttons ul li{ display: block; float: left; font-family: sans-serif; font-size: 14px; font-weight: bold; height: 25px; padding-left: 10px; padding-right: 10px; padding-top: 10px; }
        .fixed-bar-buttons ul li:hover{ background-color: #605F5F; }
        #content-panel{ float: left;margin-top: 40px; }
</style>
</head>

<body>
 <div id="top-floating-bar">
        <div class="fixed-bar-buttons">
            <ul class="nav">
                <li><a href="#section2">REFERENCIE</a></li>
                <li><a href="#section3">KONTAKT</a></li>
            </ul>
        </div>
    </div>
<div id="section2"> Section2 content</div>
<div id="section3"> Section3 content</div>
...

代码没问题,一切正常。我需要做的是仅在 section2 和 section3 上修改菜单并添加“UP”按钮。

当我加载页面时,我不需要“向上”按钮,因为它不可能向上并且在那里令人困惑,所以我只有向下滚动时才需要它。是否可以仅使用 CSS(1,2,3)?谢谢!

4

1 回答 1

1

不可能,因为您必须获取文档的垂直偏移量才能知道用户是在页面顶部还是向下滚动。需要垂直偏移来决定是否显示向上按钮。

有一种使用 JS 的方法,但是如果您要求仅使用 CSS 的解决方案,我已经给您带来了坏消息:P

于 2013-03-03T21:01:56.680 回答