jquery offset()을 이용한 부드러운 스크롤 이동

by 조쉬 posted Sep 01, 2016
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄
<div id="cont">본문 내용...</div>
<a href="#cont" class="scroll">Scroll to cont</a>


html



js

jQuery(document).ready(function($){

    $(".scroll").click(function(event){

    event.preventDefault();

 $('html,body').animate({scrollTop:$(this.hash).offset().top}, 500);
        //offset()함수로 위치를 찾음
    });
});