简体   繁体   English

粘性div从页面底部开始-保持顶部

[英]Sticky div starting at bottom of the page - stick to the top

I have a holding page for a website working as desired currently. 我目前正在为网站按要求保留网页。 Some Vegas running background fades and a simple nav bar down the bottom. 一些维加斯(Vegas)的运行背景逐渐消失,底部有一个简单的导航栏。 Currently fixed to the bottom of the page with: 目前已通过以下方式固定在页面底部:

Position: absolute; bottom: 0;

View here: www.gigabang.co 在这里查看: www.gigabang.co

I would like to develop it so that the the sit loads to that page, then the user can scroll down to reveal content. 我想对其进行开发,以便将坐席加载到该页面,然后用户可以向下滚动以显示内容。 The Footer would scroll with the page to reveal the content and then stick at the top of the page. 页脚将滚动页面以显示内容,然后粘贴在页面顶部。

I have managed to rudimentarily implement some stickUp jQuery that gets the 'footer' to stick to the top of the page, but Ive had to remove the position: absolute to get it to function. 我已经成功地实现了一些stickUp jQuery,使“页脚”停留在页面顶部,但我不得不删除位置:绝对使其起作用。

Test Page 测试页

Is there a way to get a div to start stuck to the bottom of the browser window and stick to the top after a scroll? 有没有办法让div开始停留在浏览器窗口的底部,并在滚动后停留在顶部? Also ive had to remove the Vegas jQuery code to get the stickUp stuff to work too. 我还必须删除Vegas jQuery代码才能使stickUp内容也能正常工作。 Can anyone see why that would be? 谁能知道为什么会这样吗?

Thanks for your help! 谢谢你的帮助! -m -米

stickUp Script: stickUp脚本:

<script src="gigabang/stickUp.js"></script>
<script type="text/javascript">
          //initiating jQuery
          jQuery(function($) {
            $(document).ready( function() {
              //enabling stickUp on the 'footer' class
              $('.footer').stickUp();
            });
          });

        </script>

Vegas Script: 拉斯维加斯剧本:

<!--<script type="text/javascript">
$(function() {
$.vegas('slideshow', {
delay: 8000,
backgrounds:[
{ src:'gigabang/WEBBG2.jpg', fade:1000 },
{ src:'gigabang/WEBBG5b.jpg', fade:1000 },
{ src:'gigabang/WEBBG6.jpg', fade:1000 },
{ src:'gigabang/WEBBG1.jpg', fade:1000 } ]
});$.vegas('overlay', {
src:'gigabang/vegas/overlays/13.png'
});
});
</script>

您可以在css3中使用align-content:flex-end使用Flex属性。

Do you mean like this? 你是这个意思吗

http://codepen.io/chrissp26/pen/xEAqC http://codepen.io/chrissp26/pen/xEAqC

HTML 的HTML

<h1>Footer Scroll</h1>
<footer id="footer">Footer</footer>

CSS 的CSS

body {
  font-family: "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
}

h1 {
  font-family: "Segoe UI Light", "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
  color: #999;
  font-weight: normal;
  margin: 0;
}

footer {
  background: #008aca;
  padding: 10px;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}
.fixed {
  position: fixed;
  top: 0;
  bottom: auto;
}

JS JS

$(document).on("ready", function(){

  sortTheFooterOut();

});

function sortTheFooterOut() {

  footer = $("#footer");

  $(window).on("scroll", function(){

    if ($(window).scrollTop() > 0) {
      footer.addClass("fixed");
    } else {
      footer.removeClass("fixed");
    }

  });  
}

Alternate JS with Animation 带有动画的备用JS

$(document).on("ready", function(){

  sortTheFooterOut();

});

function sortTheFooterOut() {

  footer = $("#footer");

  $(window).on("scroll", function(){

    if ($(window).scrollTop() > 0) {

      if (!footer.hasClass("fixed")) {
      footer.fadeOut(250,function(){

        footer.addClass("fixed").fadeIn(250);

      });
      }
    } else {
      footer.fadeOut(250,function(){

        footer.removeClass("fixed").fadeIn(250);

      });
    }

  });  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM