【问题标题】:One Page Scroll footer doesn't show一页滚动页脚不显示
【发布时间】:2017-05-12 19:52:33
【问题描述】:

我正在为我的作品集使用这个插件https://github.com/peachananr/onepage-scroll。它工作正常,我唯一的问题是页脚没有以我想要的高度显示(高度:150px)。

<div class="main">
<div class="section">1</div>
<div class="section">2</div>
<div class="section">3</div>
<footer>Text</footer>
</div>

如果我将类部分添加到页脚,它将起作用,但它会使页脚高度为 100%。

我找到了另一个插件http://alvarotrigo.com/fullPage/ 可以解决这个问题,但我不想因为一个问题而改变它。

如果有人能帮我解决这个问题,我将非常感激。

【问题讨论】:

  • 为什么不问问插件作者?
  • 尝试修复页脚底部
  • 我们能不能看到一个 jsfiddle 或者更多的代码,它可能是各种各样的东西。尝试最小高度而不是高度。
  • 您实际上没有指定页脚是否小于 150 像素或更大。一定要包含一些代码,但特别要提到这一点。

标签: jquery css


【解决方案1】:

如果函数:

this.moveDown = function(e) {

之后:

if (i.loop == true) {
    pos = 0;
    r = document.querySelector(i.sectionContainer + "[data-index='1']");
  }

添加:

   /*VM Cusom code for footer */
      else if(i.footer) {
        const footer = document.querySelector(i.footer);
        const footerHeight = footer.offsetHeight;
        const footerStyle = window.getComputedStyle(footer);
        const footerOuterHeight = footerHeight + parseInt(footerStyle.marginTop)  + parseInt(footerStyle.marginBottom);
        const footerPercent = footerOuterHeight / e.offsetHeight;
        if(pos >= ((t-1) * -100)){
          pos = pos - (footerPercent * 100);
          r = document.querySelector(i.sectionContainer + "[data-index='" + (parseInt(t)) + "']");
        }
        else {
          return;
        }
      }
    /*VM Cusom code for footer */

函数中的AND:

  this.moveUp = function(e) {

之后:

if (!r) {
      if (i.loop == true) {
        pos = (u - 1) * 100 * -1;
        r = document.querySelector(
          i.sectionContainer + "[data-index='" + u + "']"
        );
      }
      else {
        return;
      }
    }

添加:

else if(t == u && (pos < ((t-1) * -100))) {
  pos = (r.dataset.index) * 100 * -1;
  r = document.querySelector(
    i.sectionContainer + "[data-index='" + u + "']"
  );
}

在初始化时将选择器添加到您的页脚

onePageScroll(".home", { 
    footer: "footer" 
});

【讨论】:

    【解决方案2】:

    我没有看到任何内置的方法来做到这一点。你愿意修补插件吗?如果是这样,行后:

    $.fn.transformPage = function(settings, pos, index) {
    

    添加:

    if (pos <= -(total - 1) * 100) {
        footer_height = sections.eq(-1).height();
        footer_percent = footer_height / $(this).height();
        pos = pos + 100 - (footer_percent * 100);
    }
    

    在 CSS 上,假设您的页脚位于 .page3

    .onepage-wrapper .section.page3 {
        height: 150px;
    }
    

    See it working.

    【讨论】:

    【解决方案3】:

    您可以在 css 中尝试这样的重要操作:

    footer {
     height: 150px !important;
    } 
    

    【讨论】:

    • 这可以工作,除非通过插件在 js 中设置高度。
    • @SergChernata 仅当该高度设置为 !important 时。否则,它仍然会被覆盖,因为它被设置为 !important..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 2014-03-02
    • 2013-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多