상단으로 를 상하 이동과 퍼센트 표시하기(다크모드추가)
[재 업로드]
이렇게 됩니다.
1. 파일(button_top.php)을 /lib 또는 /theme/사용테마/lib 에 넣으세요.
2. tail.sub.php의 제일 위쪽 ?>바로 위에 아래를 복사하여 붙여넣기 하세요.
[code]
$config['cf_theme'] ? include_once(G5_THEME_PATH.'/lib/button_top.php') : include_once(G5_PATH.'/lib/button_top.php');
[/code]
끝..
button_top.php 내용
[code]
<button type="button" id="button_top">
<i class="fa fa-arrows-v" aria-hidden="true"></i><span class="sound_only">상단으로</span>
</button>
<script>
jQuery(function($) {
var $elem = $("html, body");
var where = 0;
$("#button_top").on("click", function() {
var windowHeight = $(document).height() - $(window).height();
var winhalf = windowHeight * 0.5; // Calculate the new winhalf value
if ($elem.scrollTop() < winhalf) {
$elem.animate({ scrollTop: $elem.prop("scrollHeight") }, 400);
where = 1;
} else {
$elem.animate({ scrollTop: 0 }, 400);
where = 0;
}
});
});
$(document).ready(function() {
$(window).scroll(function() {
var windowHeight = $(document).height() - $(window).height();
var winhalf = windowHeight * 0.5; // Calculate the new winhalf value
var scrollPos = $(document).scrollTop();
var scrollPercent = (window.scrollY / (document.documentElement.scrollHeight - window.innerHeight)) * 100;
var $buttonTop = $('#button_top'); // Selector variable
if (scrollPos > winhalf) {
$buttonTop.css({
"border-color": "red",
"color": "red"
}).html("<i class='fa fa-arrow-up' aria-hidden='true'></i>");
} else {
$buttonTop.css({
"border-color": "blue",
"color": "blue"
}).html("<i class='fa fa-arrow-down' aria-hidden='true'></i>");
}
if ($('#scroll_percentage').length === 0)
{
$('<p id="scroll_percentage"></p>').appendTo($buttonTop);
}
$('#scroll_percentage').text(Math.round(scrollPercent));
<?php if(file_exists(G5_THEME_PATH.'/css/default_dark.css')){ ?>
if (scrollPos > 100 && scrollPos < 200) {
$('#button_top').css("display", "none");
$('.fix_ch').css("display", "block");
} else {
$('.fix_ch').css("display", "none");
$('#button_top').css("display", "block");
}
<?php } ?>
if (!g5_is_mobile) {
$('#gnb').css({
"display": "block",
"z-index": "10000"
});
if (scrollPos > 186) {
$('#gnb').css({
"position": "fixed",
"top": "0",
"width": "100%"
});
} else {
$('#gnb').css({
"position": "relative"
});
}
}
});
});
</script>
<style>
#top_btn, .fix_ch {
display:none
}
#button_top {
position: fixed;
bottom: 20px;
right: 3px;
width: 43px;
height: 43px;
line-height: 40px;
border-radius: 50%;
border: 1px solid #33333310;
color: #333;
text-align: center;
font-size: 15px;
z-index: 220;
background: rgba(255, 255, 255, 0.5);
}
#button_top:hover {
border-color: #3059c750;
background: #3059c750;
color: #333;
}
#scroll_percentage {
font-size: 12px;
margin-top: -27px;
font-weight: bold;
z-index: 999;
}
</style>
[/code]
스크롤 시 메뉴가 상단에 고정됨니다.
댓글 7개
그냥 출력코드를 깔끔하게, /lib 폴더에 넣은 경우와 테마안 lib폴더에 넣은 경우 사용하는 코드를 달리해서 정리해주는 게 좋을 듯 합니다.
모바일에서 더욱 정교하도록 코드를 한군데 수정 하였습니다.
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 2635 | 5개월 전 | 598 | ||
| 2634 | 5개월 전 | 589 | ||
| 2633 |
|
6개월 전 | 500 | |
| 2632 | 6개월 전 | 558 | ||
| 2631 |
세르반데스
|
6개월 전 | 529 | |
| 2630 | 6개월 전 | 715 | ||
| 2629 | 6개월 전 | 401 | ||
| 2628 | 6개월 전 | 406 | ||
| 2627 |
이슈DEV
|
6개월 전 | 628 | |
| 2626 |
welcome
|
6개월 전 | 636 | |
| 2625 |
이슈DEV
|
6개월 전 | 441 | |
| 2624 | 6개월 전 | 399 | ||
| 2623 | 6개월 전 | 487 | ||
| 2622 | 6개월 전 | 340 | ||
| 2621 |
|
6개월 전 | 354 | |
| 2620 | 6개월 전 | 462 | ||
| 2619 | 6개월 전 | 457 | ||
| 2618 | 6개월 전 | 546 | ||
| 2617 | 6개월 전 | 668 | ||
| 2616 | 7개월 전 | 572 | ||
| 2615 | 7개월 전 | 400 | ||
| 2614 |
바닐라코드
|
7개월 전 | 721 | |
| 2613 | 7개월 전 | 586 | ||
| 2612 | 7개월 전 | 720 | ||
| 2611 | 7개월 전 | 953 | ||
| 2610 | 7개월 전 | 499 | ||
| 2609 | 7개월 전 | 644 | ||
| 2608 | 7개월 전 | 621 | ||
| 2607 | 7개월 전 | 567 | ||
| 2606 | 7개월 전 | 591 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기