javascript - 滚动时堆叠 div

标签 javascript jquery html css z-index

我想将博客上的帖子格式化为在用户向下滚动页面时堆叠“标题 div”。我解释这个的唯一方法是做一点 demo通过欺骗和到处使用 z-index 来模拟​​它应该看起来的样子。

我想重新创建此效果,但使其适用于博客上的帖子。这可能吗?

编辑:试图找到一种使用 javascript 来创建这种效果的方法。

这是当前的 CSS:

body {
    margin: 0;
    padding: 0;
}

h2, h3, p {
    padding: 0px;
    margin: 0px;
}

#container {
    position: relative;
    width: 360px;
    margin: 0px auto;
}

#header {
    position: fixed;
    top: 0px;
    width: 360px;
    height: 60px;
    background: #fff;
    z-index: 10;
}

#right_column {
    width: 360px;
    margin: 60px 0px 0px 0px;
}

    #right_column .first_title {
        position: relative;
        margin: 0px;
        font-size:32px;
        line-height: 30px;
        z-index: 9;
        background: #fff;
    }

    #right_column .first_fixed {
        position: fixed;
        top: 60px;
        z-index:6;
        width: 360px;
        background: #eee;
        border-top: #999 1px solid;
    }

    #right_column .first {
        position: relative;
        z-index: 5;
        background: #fff;
    }

    #right_column .second_title {
        position: relative;
        margin: 0px;
        font-size:32px;
        line-height: 30px;
        z-index: 5;
        background: #fff;
    }

    #right_column .second_fixed {
        width: 360px;
        position: fixed;
        top: 80px;
        z-index: 3;
        border-top: #999 1px solid;
        background: #eee;
    }

    #right-column .second {
        position: relative;
        z-index: 2;
    }

这是标记:

    <h2 class="first_title">This is the article title.</h2>
        <h3 class="first_fixed">This is the article title.</h3>
                 <p class="first">This is some text.</p>
    <h2 class="second_title">This is the article title.</h2>
        <h3 class="second_fixed">This is the article title.</h3>
                <p class="second">This is some text.</p>

最佳答案

我不确定您要的是什么。我想您正在尝试寻找一种替代您已经找到的方法的方法。在这种情况下,您可能想看看这个 example 中的 jQuery 航路点插件。 .. 您定义在滚动页面时触发事件的标记。
这是main page

关于javascript - 滚动时堆叠 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9087245/

相关文章:

javascript - 我如何在javascript中创建一个对象数组

javascript - 在给定日期上添加 1 天

javascript - 在表单提交时,使用表单值从 javascript 邮寄到

javascript - jquery sortable ui 在拖动到特定 div 时删除项目

javascript - 我如何通过单击按钮获得此交通灯序列???

javascript - 检查该部分的滚动顶部

javascript - 如何用不同的类名包装 DIV 标签?

javascript - Bootstrap3 Datepicker - 计算活跃日期

javascript - 固定列表定位

javascript - 多级下拉菜单 CSS JS : not working with IE