본문 바로가기

study_IT/기타

스크롤 따라 움직이는 플로팅 사이드 menu 구현하기

728x90
반응형
<script type="text/javascript">
 $(function() {  

 $( "#goTop" ).on("click" , function() {
 $('html, body').animate({scrollTop:0}, 300);
});
 
 $( "#goHome" ).on("click" , function() {
 self.location = "/index.jsp"
});
 
 });

  $(document).ready(function () {
        var tmp = parseInt($("#test_obj").css('top'));
 
        $(window).scroll(function () {
            var scrollTop = $(window).scrollTop();
            var obj_position = scrollTop + tmp + "px";
 
            $("#test_obj").stop().animate({
                "top": obj_position
            }, 500);
 
        }).scroll();
    });
</script>
<style> 
#test_obj {
        position: absolute;
        right: 50px;
        top: 250px;
        border: 1px solid #dddddd;
    }
</style>
// <body> 태그 안에 추가

<div id="test_obj">
<button type="button" class="btn btn-default" id="goTop"><a href="#"><span class="glyphicon glyphicon-menu-up" aria-hidden="true"><br/>top</span></a></button>
<button type="button" class="btn btn-default" id="goHome"><a href="#"><span class="glyphicon glyphicon-home" aria-hidden="true"><br/>home</span></a></button>
</div>



728x90
반응형