jquery - 如何创建在页面到达末尾时滚动到 View 中的页脚

标签 jquery css footer parallax

我正在尝试创建一个页脚,当您到达页面底部时,它会向上滚动到与页面内容重叠的 View 中。这有点像这个 Codepen by devkick 的反面

我的网站目前是这样的,但设计者要求新版本按上述方式工作。基本上页面停止滚动,页脚滚动到与页面重叠的 View 中。我发现了很多关于动画的东西,但我希望它只是可滚动且简单,没有 jquery 动画。我也查看了视差效果,但它们似乎都是相同的隐藏页脚,页面被挡住时会显示出来。

这是我当前的页脚设置

<div class="wrapper">
<div class="innerWrapper">
  <!--all the content!-->
</div>
</div>
    <footer>
        <div class="innerFooter">
            <!--all the content!-->
        </div>
    </footer>

还有我的一些页脚 CSS

//wrapper for everything but footer
.wrapper {
    position:relative;
    z-index:3;
    background-color: #fff;

}

//wrapper for internal content
.innerWrapper {
    text-align: center;
    width: 100vw;
}
footer {
  height: 380px;
  color:$white;
  font-size:12px;
  position:relative;
  z-index:0;
  background-color:$black;
}

footer .innerFooter {
  position: fixed;
  left: 1%;
  right: 1%;
  bottom: 1em;
  z-index: 1;
}

最佳答案

好吧,我不确定我最初想要的东西是否可以按照我最初的想法实现。我最终采用了动画方法,但它的播放方式并不像我想象的那样像动画。

var homePage = $('.homeWrap').length;

$(window).scroll(function(){
  if (homePage === 0) {
    var footerHeight = $('footer').height();

  if ($(window).scrollTop() + $(window).height() >= $(document).height() - 0)
    {
        if($('footer').data('size') == 'hide')
        {
            $('footer').data('size','show');
            $('footer').css('visibility', 'visible');
            $('footer').stop().animate({
                bottom:'0px'
            },400);
        }
    } 
    else
    {
        if($('footer').data('size') == 'show')
        {
            $('footer').data('size','hide');
            $('footer').stop().animate({
                bottom: '-'+footerHeight
            },400);

        }  
    }
  } else {}

});

$(document).ready(function() {
  if (homePage === 0) {
    var body = document.body,
    html = document.documentElement;
    $('footer').data('size','show');
    if ($('.innerWrapper').offsetHeight >= html.offsetHeight)
    {
        $('footer').data('size','hide');
    }
    else
    {
        $('footer').data('size','show');
        $('footer').stop().animate({
                bottom:'0px',
                visibility: 'visible'
            },400, function() {

            });
    }
  } else {}

});

欢迎反馈!

关于jquery - 如何创建在页面到达末尾时滚动到 View 中的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39294932/

相关文章:

javascript - Jquery - 解析从 URL 接收到的 XML

jquery - 如何识别 child 输入类型

javascript - 如何重置受 jquery 函数影响的元素

jquery - 更改背景图像 css

javascript - 如果段落有特定文本,请单击按钮

html - 网站不滚动 |内容超出页面底部 |页脚出现在顶部

PHP使用ajax刷新表格内容

html - 页脚粘在底部,但在浏览器调整大小时,页脚被推到内容顶部

html - wkhtmltopdf 正文和页脚之间的边距

html - 如何在普通 div 中使用 CSS 实现发光元素,如下所述?