간단한 스크롤 진행률 표시기 구현하기 2
<button id="scrollToTopBtn">0%</button>
<style type="text/css">
#scrollToTopBtn { position:fixed; bottom:20px; right:20px; padding:5px; font-size:11px; background-color:#E30613; color:white; border:none; border-radius:5px; cursor:pointer; opacity:0; visibility:hidden; transition:opacity 0.5s, visibility 0.5s; }
#scrollToTopBtn:hover { background-color:#FF000E; }
#scrollToTopBtn.show { opacity:1; visibility:visible; }
</style>
<script type="text/javascript">
$(document).ready(function() {
var $window = $(window);
var $scrollToTopBtn = $('#scrollToTopBtn');
var $document = $(document);
$window.scroll(function() {
var scrollPercent = Math.round($window.scrollTop() / ($document.height() - $window.height()) * 100);
$scrollToTopBtn.text(scrollPercent + '%');
if($window.scrollTop() > 200){
$scrollToTopBtn.addClass('show');
}else{
$scrollToTopBtn.removeClass('show');
}
});
$scrollToTopBtn.click(function(){
$('html, body').animate({ scrollTop: 0 }, 'slow');
});
});
</script>
우측에 위로 가기 버튼과 동일 하지만 퍼센트로 표시를 해주고
버튼을 누르게 되면 상단으로 이동되는 스크립트 입니다.
댓글 2개
감사합니다.
감사합니다.
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4946 | node.js | 6년 전 | 2610 | ||
| 4945 | node.js | 6년 전 | 2382 | ||
| 4944 | node.js | 6년 전 | 2520 | ||
| 4943 | node.js | 6년 전 | 2272 | ||
| 4942 | node.js | 6년 전 | 2250 | ||
| 4941 | node.js | 6년 전 | 2720 | ||
| 4940 | node.js | 6년 전 | 1867 | ||
| 4939 | node.js | 6년 전 | 1995 | ||
| 4938 | node.js | 6년 전 | 2459 | ||
| 4937 | node.js | 6년 전 | 2250 | ||
| 4936 | node.js | 6년 전 | 2322 | ||
| 4935 | node.js | 6년 전 | 2136 | ||
| 4934 | node.js | 6년 전 | 2442 | ||
| 4933 | node.js | 6년 전 | 2247 | ||
| 4932 | node.js | 6년 전 | 2687 | ||
| 4931 | node.js | 6년 전 | 2070 | ||
| 4930 | node.js | 6년 전 | 1999 | ||
| 4929 | node.js | 6년 전 | 8632 | ||
| 4928 | node.js | 6년 전 | 3750 | ||
| 4927 | node.js | 6년 전 | 2394 | ||
| 4926 | node.js | 6년 전 | 2504 | ||
| 4925 | node.js | 6년 전 | 2084 | ||
| 4924 | node.js | 6년 전 | 3374 | ||
| 4923 | node.js | 6년 전 | 2221 | ||
| 4922 | node.js | 6년 전 | 1991 | ||
| 4921 | node.js | 6년 전 | 2046 | ||
| 4920 | node.js | 6년 전 | 1765 | ||
| 4919 | node.js | 6년 전 | 2032 | ||
| 4918 | node.js | 6년 전 | 2180 | ||
| 4917 | node.js | 6년 전 | 2396 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기