2012-02-23 13 views

答えて

1

これはおそらくあなたを助けることができます。 https://github.com/jami/Sticky-Attachment

+0

この任意の例?私は私のオフィスでgitアカウントを持っていないので、私はこれをフォークすることはできません –

+0

gihubからコードをダウンロードするにはgitは必要ありません。右端にダウンロードリンクがあります:https://github.com/jami/Sticky-Attachment/downloads – Candide

0

はここで尋ね長いので、質問への格安、迅速なソリューションです。..

コード

var footerstickyHeight = $('.footer-sticky').height(); 
 
var windowHeight = $(window).height(); 
 
$(window).scroll(function() { 
 
    var footerToTop = $('.footer').offset().top; 
 
    var triggerAt = footerToTop + footerstickyHeight; 
 
    var windowToTop = $(window).scrollTop(); 
 
    if (windowToTop + windowHeight > triggerAt) { 
 
    $('.footer-sticky').removeClass('fixed'); 
 
    } else { 
 
    $('.footer-sticky').addClass('fixed'); 
 
    } 
 
})
html, body { 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow-x: hidden; 
 
} 
 
div { 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
    flex-direction: column; 
 
    width: 100vw; 
 
} 
 
.header { 
 
    height: 111px; 
 
    background-color: orange; 
 
} 
 
.main { 
 
    height: 888px; 
 
    background-color: gray; 
 
} 
 
.footer { 
 
    background-color: dimgray; 
 
} 
 
.footer-sticky { 
 
    height: 33px; 
 
    background-color: dimgray; 
 
} 
 
.footer-sticky.fixed { 
 
    position: fixed; 
 
    bottom: 0; 
 
    left: 0; right: 0; 
 
} 
 
.footer-more { 
 
    height: 66px; 
 
    background-color: dimgray; 
 
    border-style: solid; 
 
    border-color: hsla(0, 0%, 0%, 0.1); 
 
    border-width: 1px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="header">Header</div> 
 
<div class="main">Content</div> 
 
<div class="footer"> 
 
    <div class="footer-sticky fixed">sticky footer</div> 
 
    <div class="footer-more">more information</div> 
 
</div>

フィドル

https://jsfiddle.net/Hastig/ztox79sd/

クレジット

https://stackoverflow.com/a/20675351/3377049

関連する問題