html소스는 페이지 하단에 삽입
<a href="#" id="top_btn">상단으로</a>
제이쿼리 스크립트는 그보다 아래에 삽입
<script>
$(function() {
$("#top_btn").on("click", function() {
$("html, body").animate({scrollTop:0}, '500');
return false;
});
});
$( window ).scroll( function() {
if ( $( this ).scrollTop() > 200 ) {
$( '#top_btn' ).fadeIn();
} else {
$( '#top_btn' ).fadeOut();
}
} );
</script>
css 소스 삽입
#top_btn{position:fixed;bottom:10%;right:5%;display:none;width:50px;height:50px;border-radius:5px;background-color:#fff !important;text-indent:-9999px;background:url("../img/top_btn.gif") center center no-repeat; overflow:hidden;opacity:0.8;z-index: 999;}
'웹 퍼블리싱 > Javascript' 카테고리의 다른 글
유용한 제이쿼리 슬라이드 (0) | 2018.08.14 |
---|---|
쓸만한 제이쿼리 예제 사이트 (0) | 2015.07.17 |
제이쿼리 배경 슬라이드 플러그인 (0) | 2015.07.17 |