CSS

[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>


결과보기


 


분류 제목
border CSS - border-bottom-left-radius 속성 - 테두리하단왼쪽모서리둥글게 (= border…
func CSS - attr() 함수 - 선택요소의 속성값 반환. (= attr함수 = 어트르함수) ※ 속성값얻기
selector CSS - :last-of-type 가상선택자 - 지정타입 마지막자식요소 (순서선택자,타입선택자, IE9)
flex CSS - flex-shrink 속성(I) ★ - 동일컨테이너 안 나머지 플렉스아이템에 비해 얼마나 줄어들지…
selector CSS - .class1.class2 클래스선택자 ★★★ - 두 클래스가 (모두/함게/둘다/동시) 정의된 요…
selector CSS - :indeterminate 가상선택자 - 불확정요소 선택 (= :indeterminate선택자 =…
border CSS - border-bottom-style 속성 - 테두리하단스타일 (= 보더바텀스타일) (상속 X)
flex CSS - flex-direction 속성(C) ★★ - 기본축 방향 결정. (= flex-direction…
selector CSS - :link 가상선택자 - 미방문링크 (= 링크선택자)
selector CSS - :nth-last-child(n) 가상선택자 ★★★ - (그 부모의) 마지막n번째 자식요소 (= …
selector CSS - :required 가상선택자 - 필수입력요소 (= required속성있는요소, IE10)
transform CSS - transform-style 속성 - 중첩요소를 3D공간에서 표시 방법 (= transform-s…
intro CSS - 브라우저 접두어 (= vendor prefix = 벤더 프리픽스)
animation CSS - animation-play-state 속성 - 애니재생상태 (= 애니작동상태설정 = 움직임 재생/…
css CSS - currentcolor 키워드 - 현재 글자색 속성값을 그대로 사용 (= 커런트컬러 속성값)
21/35
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티
웹유틸
회원센터
홈짱닷컴 PC버전 로그인