首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使div从底部开始

使div从底部开始
EN

Stack Overflow用户
提问于 2019-11-05 22:02:37
回答 1查看 124关注 0票数 3

这是我的网站的测试图片。目前,当你向下滚动屏幕时,顶部的区块会变得更大,但它来自顶部。我怎么才能让它从底部上来呢?这与偏移有关吗?div称为stem,底部div称为timeline

代码语言:javascript
运行
复制
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();
    }
  });
}
代码语言:javascript
运行
复制
.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%;

}
代码语言:javascript
运行
复制
<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中尝试了一些东西,但是很多溢出都是多余的。

EN

回答 1

Stack Overflow用户

发布于 2019-11-05 22:46:24

我得到了我想要的答案

代码语言:javascript
运行
复制
stem.offset({top:timelineot});

timelineot+50timelineot-50测试

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58713008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档