javascript - 将通知消息滚动到固定菜单底部

标签 javascript jquery html css

我想将通知消息滚动到顶部固定菜单的底部,但正文内容继续滚动,只有通知框将固定在固定顶部菜单的底部。 这是一个fiddle example:

html:

<div class="menu-fixed">I am a fixed menu! </div>
            <div class="bodyContent">I am the body content of this page
            <div class="notification">I am a notification message! 
                      Scroll me to the bottom of top menu only! and back.</div>
    </div>

CSS:

.menu-fixed{
    position: fixed;
    text-align: center;
    width: 100%;
    height: 100px;
    border:1px solid blue;
    background: rgba(0,0,0,0.3);
    font-size:30px;
}

.bodyContent{
    padding-top:120px;
    height:1000px;
    width:100%;
    background:lime;
    text-align: center;
    font-size:50px;
 }
.notification{
    height: 100px;
    left: 80%;
    position: absolute;
    width: 200px;
    background: rgba(255,255,255,0.9);
    font-size:20px;
}

谁能帮我解决这个 scrollTo 函数? ty.

最佳答案

如果我正确理解你的问题,这应该会让你朝着正确的方向前进:

$(document).ready(function() {
    $(window).scroll(function() {
        var menuHeight = $(".menu-fixed").outerHeight();
        var windowScrollTop = $(window).scrollTop();

        if (windowScrollTop > 80) {
            $(".notification").css({ top: windowScrollTop + menuHeight });
        }
        else {
            $(".notification").css({ top: 'auto' });
        }
    });
});

我已经更新了你的 JSFiddle:http://jsfiddle.net/VPzxG/1823/

关于javascript - 将通知消息滚动到固定菜单底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22046928/

相关文章:

javascript - ng-if 不在 ng-repeat 中比较 $index

javascript - 保留悬停在链接上的效果

html - 让文本溢出工作而不重叠

javascript - 将 jQuery 事件应用于所有类元素?

PHP 数据库 - 不想显示 javascript 代码

jQuery 插入元素 .before() 和 .after() 无法按预期工作,我做错了什么?

javascript - 如何将 JSON 对象存储为 select 标签中的选项值?

javascript - 如何在 RaphaelJS 中使用矩阵

javascript - 当涉及嵌套元素时,如何使用 jQuery 来操作 html 表单?

javascript - Overflow-x 滚动属性在桌面上有效,但在手机上无效