javascript - 使div从底部开始

标签 javascript jquery html css

这是我网站的测试图片。当前,当您向下滚动屏幕时,顶部的 block 会变大,但它来自顶部。我如何让它从底部出现?跟offset有关系吗? div 称为stem,底部div 称为timeline

enter image description here

function showStem() {
  var stemb = $(".stem-background");
  var stem = $(".stem");
  var timeline = $(".timeline");
  var timelineot = timeline.offset().top;
  var h = document.documentElement.clientHeight;
  
  $(window).scroll(function() {
    var scroll = $(window).scrollTop();
    if (scroll > timelineot - h) {
      stemb.hide();
      stem.show();
      stem.height(scroll + h - timelineot);
    } else {
      stemb.hide();
      stem.hide();
    }
  });
}
.timeline {
    background: #112C30;
    margin: 0;
    padding: 0;
    font-family: sans-serif;
    font-size: 15px;
    line-height: 26px;
    color: #B9CFD0;
    overflow: hidden;
}

.timeline a {
    color: #B9CFD0;
    text-decoration: none;
    border-bottom: 1px solid #B9CFD0;
}

.timeline h1, h2, h3, h4, h5, h6 {
    font-family: 'Comfortaa', cursive;
}

.main-content {
    margin: 0 auto;
    position: relative;
}

.main-content .section-inner, .main-content .post-wrapper {
    *zoom: 1;
}

.main-content .section-inner:before, .main-content .section-inner:after, .main-content .post-wrapper:before, .main-content .post-wrapper:after {
    content: "";
    display: table;
}

.main-content .section-inner:after, .main-content .post-wrapper:after {
    clear: both;
}

.section .section-inner {
    margin: 0 auto;
    width: 1024px;
}

@media only screen {
    .section .section-inner {
        width: auto;
        max-width: 1024px;
    }
}


.stem-wrapper {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 50%;
    z-index: auto;

}


.stem-wrapper.color-yellow .stem-background {
    background: #E9E566;
}

.stem-wrapper.color-green .stem-background {
    background: #35C189;
}

.stem-wrapper.color-white .stem-background {
    background: #FFF;
}

.stem-wrapper .stem, .stem-wrapper .stem-background {
    position: absolute;
    top: 0;
    left: -30px;
    width: 60px;
}

.stem-wrapper .stem{
    background: #1e4f56;
    overflow: hidden;
    height: 100%;
}

.stem-wrapper .stem-background {
    background: #ecf6f9;
    height: 50%;

}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="timeline">
  <div class="stem-wrapper">
    <div class="stem"></div>
    <div class="stem-background"></div>
  </div>
  <!-- more content -->
</div>

我在 CSS 中尝试了一些东西,但很多溢出都是多余的。

最佳答案

我得到了我一直在寻找的答案

stem.offset({top:timelineot});

通过timelineot+50timelineot-50测试

关于javascript - 使div从底部开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58713008/

相关文章:

javascript - 使用 jQuery ajax() 时 FormData 为空

javascript - 为什么使用map、forEach和for循环插入数据库时​​数组的顺序不同

javascript - 退出嵌入在另一个函数中的两个javascript函数

javascript - 如何将 DRY 应用于一系列具有几乎相同 <div></div> block 的 HTML 文件?

javascript - 在div中显示英文字母

javascript - 如何高亮:active element using javascript?

jquery - FancyBox (fancyapps) 内容在顶部

c# - knockout View 模型+所选项目->嵌套列表 "not defined"

html - 垂直居中,高度可变

html - 获取具有相同名称的多个表单值( bool 大小写)