$(function() {
$(window).scroll(function() {
if ($(this).scrollTop() > 250) {
$('#topBtn').fadeIn();
} else {
$('#topBtn').fadeOut();
}
});
$("#topBtn").click(function() {
$('html, body').animate({
scrollTop : 0
}, 400);
return false;
});
});
<div style="margin-bottom:2000px;">
빈 공백
</div>
<a id="topBtn" href="#">TOP</a>
a#topBtn {
position: fixed; /* 포지션 고정 */
right: 2%; /* 오른쪽에서 2% - %도 할수 있음*/
bottom: 5px; /* 밑에서 5px */
display: none; /* 보여지지 없음 - 기본적으로 안보여지게 */
z-index: 9999; /* 포지션을 먼저 지정후 z-좌표(레이어) : 9999입니다. */
}
External resources loaded into this fiddle: