• 회원가입
  • 로그인
  • 구글아이디로 로그인

[css] CSS - Smooth Scroll (부드러운 스크롤 = 부드럽게이동) ※ 클릭 상하 이동

목차
  1. CSS 방법 - 크로스 브라우징 X
  2. jQuery 방법 - 크로스 브라우징 O

 

CSS 방법 - 크로스브라우징 X

(∵ IE, Safari 지원 X)

 

<style>

html {scroll-behavior: smooth; /* 부드러게 */}

#section1 {height: 600px; background-color: pink;}

#section2 {height: 600px; background-color: yellow;}

</style>


<div class="hz" id="section1">

  <h2>Section 1</h2>

  <a href="#section2">섹션2로 이동</a>

</div>


<div class="hz" id="section2">

  <h2>Section 2</h2>

  <a href="#section1">섹션1로 이동</a>

</div>

 

결과보기 


jQuery 방법 - 크로스 브라우징 O

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<script>

$(document).ready(function(){

  $("a").on('click', function(event) {

    if (this.hash !== "") {

      event.preventDefault();

      var hash = this.hash;

      $('html, body').animate({

        scrollTop: $(hash).offset().top

      }, 800, function(){

        window.location.hash = hash;

      });

    } 

  });

});

</script>


<style>

#section1 {height: 600px; background-color: pink;}

#section2 {height: 600px; background-color: yellow;}

</style>


<div class="hz" id="section1">

  <h2>Section 1</h2>

  <a href="#section2">섹션2로 이동</a>

</div>


<div class="main" id="section2">

  <h2>Section 2</h2>

  <a href="#section1">섹션1로 이동</a>

</div>


결과보기


 


분류 제목
scroll CSS - scroll-margin-inline-end 속성 -
scroll CSS - scroll-margin-right 속성 -
border CSS - border-block-start-width 속성 -
border CSS - border-inline-style 속성 -
css CSS - break-before 속성 - 지정요소 앞에서 (페이지중단/컬럼중단/영역중단) 발생 여부 지정 …
scroll CSS - scroll-margin-block-start 속성 -
scroll CSS - scroll-padding-left 속성 -
border CSS - border-inline-color 속성 -
border CSS - border-start-start-radius 속성 -
selector CSS - ::view-transition-new 가상선택자 -
css CSS - hyphens 속성 - 긴 텍스트 단어에서 하이픈 표시 방법 지정 (= hyphens속성 = 하이…
css CSS - place-self 속성 - 그리드셀 내 개별 아이템 (수직/수평) 정렬 (= place-self…
scroll CSS - scroll-margin-block-end 속성 -
border CSS - border-block-end-width 속성 - 블락방향 끝테두리 너비(=두께) 지정 (= bo…
border CSS - border-inline-start-width 속성 -
scroll CSS - scroll-snap-stop 속성 -
css CSS - offset-path 속성 -
scroll CSS - scroll-snap-align 속성 -
selector CSS - ::view-transition-old 가상선택자 -
font CSS - font-kerning 속성 - 문자 모양 고려해, 문자 사이 간격 지정 (= font-kerni…
6/27
목록
찾아주셔서 감사합니다. Since 2012