반응형
출처: http://stackoverflow.com/questions/22413203/bootstrap-affix-back-to-top-link
Now that I understand the Affix component better, I have come up with the solution. After specifying a top offset and adjusting the CSS, it's working nicely. The link will scroll into view and then "pin" to the bottom. For pages which do not have a scroll bar, the link is never enabled. I've updated the JS Fiddle (here) with a working example. Key pieces are:
HTML:
<!-- child of the body tag -->
<span id="top-link-block" class="hidden">
<a href="#top" class="well well-sm" onclick="$('html,body').animate({scrollTop:0},'slow');return false;">
<i class="glyphicon glyphicon-chevron-up"></i> Back to Top
</a>
</span><!-- /top-link-block -->
JS:
<script>
// Only enable if the document has a long scroll bar
// Note the window height + offset
if ( ($(window).height() + 100) < $(document).height() ) {
$('#top-link-block').removeClass('hidden').affix({
// how far to scroll down before link "slides" into view
offset: {top:100}
});
}
</script>
CSS:
<style>
#top-link-block.affix-top {
position: absolute; /* allows it to "slide" up into view */
bottom: -82px;
left: 10px; /* right: 15px; 오른쪽에 위치시킬때 */
}
#top-link-block.affix {
position: fixed; /* keeps it on the bottom once in view */
bottom: 18px;
left: 10px;
}
</style>
Note: I was not able to use the affix bottom offset (example) to hide the link for short pages due to a bug with affix container height calculation (Bootstrap Issue # 4647). I'm sure there is a workaround and would welcome the solution to this method.
반응형
'Web > Bootstrap' 카테고리의 다른 글
Bootstrap를 이용한 마우스 오버시 Tooltip 설명 나오는 예제 (0) | 2021.02.04 |
---|---|
Bootstrap 4 달력 : datetimepicker (Bootstrap 3버전 업그레이드 버전) 인기 달력 (2) | 2020.01.15 |
Bootstrap 4에서 svg 아이콘 사용하기 (0) | 2018.12.05 |
Bootstrap 4 Display 유틸리티 - table columns 을 hide 처리하기 (0) | 2018.11.30 |
Bootstrap 토글 접기 Collapsible collapse 기능 (0) | 2017.08.23 |
Bootstrap 반응형 테이블 FooTable (Plug In) 검색/페이지네이션 추가됨 (0) | 2017.08.17 |
jQuery Bootgrid 간편한 그리드 표시 (페이지네이션, 검색 기능 PlugIn) (0) | 2017.07.22 |
Bootstrap Table Grid sort 처리 - Datatables (0) | 2017.03.09 |
도움이 되셨다면 하트모양의 "♡ 공감"을 눌러주시면 큰 격려가 됩니다.
(로그인하지 않으셔도 가능)
(로그인하지 않으셔도 가능)