2015-02-05 2 views
1

내 페이지에 효과를 생성하고 있습니다. 뉴스 페이지가 있는데 사용자가 페이지를 스크롤하면 화면 하단에있는 버튼이있는 부동 div가 표시됩니다. 화면 하단에 붙어 있어야합니다. 그러나 그것이 바닥 글 내용에 도달하지 않을 때까지 붙어있을 것입니다. 나는 이것을 어떻게하는지 모른다. 이걸로 나를 도울 수 있니? 여기 바닥 글 태그가 감지되면 아래쪽에 떠있는 div를 제거하는 방법은 무엇입니까?

$(window).scroll(function() { 
    if($(window).scrollTop() + $(window).height() == $(document).height()) { 
     $(".floating_content").removeAttr('style'); 
     //$(".fix_content").css('margin-bottom':'174px'); 
    } else { 
     $(".floating_content").css({'position':'fixed','bottom':'0','width':'100%','z-index':'99'}); 
    } 
}); 

내 바이올린입니다 :

HTML :

<header>Header Goes Here</header> 
<div class="container"> 
    <div class="news"> 
     <p>Very long content here...</p> 
    </div> 
</div> 
<div class="floating_content"> 
    <button>Next Page</button> 
</div> 
<footer>Footer Here</footer> 

CSS :

header { 
    height: 50px; 
    background: #ccc; 
    color: #fff; 
    text-transform: uppercase; 
    padding: 5px; 
    font-family: verdana; 
    text-align: center; 
} 

.news { padding: 10px } 

.floating_content { 
    display: none; 
    position: fixed; 
    bottom: 0; 
    width: 100%; 
    padding: 5px; 
    text-align: center; 
    background: #ccc; 
} 
footer { 
    background: #000; 
    color: #fff; 
    text-align: center; 
    height: 50px 
} 

JQuery와 여기

내 코드의 비트의 JSFiddle

+0

가능한 복제본 [Float a div 오른쪽 하단 모서리에 있지만 내부 바닥 글] (http://stackoverflow.com/questions/18455453/float-a-div-at-the-bottom-right-corner-but-not-inside-footer) –

답변

1

업데이트 :

$(window).scroll(function() { 
     if($(window).scrollTop() + $(window).height() == $(document).height()) { 
     $(".floating_content").show(); 
    } 
}); 

UPDATED2 : 내가 설정하고 같이 relative로 부동 내용의 위치를 ​​변경하기 위해 노력하고있어

:

.floating_content { 
    display: none; 
    position:relative; //here 
    bottom: 0; 
    width: 100%; 
    padding: 5px; 
    text-align: center; 
    background: #ccc; 
} 

here

Jsfiddle 업데이트
+0

죄송 합니다만 작동하지 않습니다. 바닥 글의 맨 위에 부동 div를 배치하고 싶습니다. 바닥 글이 브라우저에 표시됩니다. – Jerielle

+0

죄송합니다. 원하지 않는 것을 유감스럽게 생각합니다. 내가 원하는 것은 플로팅 div가 먼저 숨길 것입니다. 그런 다음 사용자가 페이지를 스크롤하면 부동 div가 페이지 자체가 아니라 브라우저 하단에 표시됩니다. 그런 다음 플로팅 div를 스크롤 할 때 브라우저 바닥에 스틱이있을 때까지 바닥 글의 윗부분에 도달하면 바닥 글의 맨 위에 머무르게됩니다. 그런 다음 사용자가 페이지를 위로 스크롤하면 부동 div가 페이지 하단에 다시 표시됩니다. – Jerielle