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>


결과보기


 


분류 제목
gradient CSS - repeating-linear-gradient () 함수 - 반복 선형 그레이디언트 ※ 패턴 배경
image CSS - object-fit 속성 - 컨테이너에 맞게 '이미지/비디오' 크기 조정 방법 지정 (= obje…
border CSS - border-image-source 속성 - 테두리 이미지 주소 (= border-image-so…
border CSS - border-right 속성 - 테두리우측일괄 (= 테두리오른쪽일괄 = border-right속성…
pagination CSS - 페이징 - 가운데 정렬 (Centered Pagination)
animation CSS - animation-timing-function 속성 - 애니재생중속도변화 (= 움직임 중 속도변경…
border CSS - border-left-style 속성 - 테두리좌측모양 (= 테두리왼쪽모양 = border-lef…
border CSS - border-image-width 속성 - 테두리 이미지 너비 (= border-image-wid…
border CSS - border-right-color 속성 - 테두리우측색상 (= 테두리오른쪽색상 = 테두리우측색깔…
border CSS - border-top-style 속성 - 테두리상단모양 (= 테두리상단스타일 = border-top…
color CSS - RGBA , HSL , HSLA , opacity - (색상코드)
transform CSS - backface-visibility 속성 - 3D요소 뒷면 노출 여부. (= backface-vi…
border CSS - border-right-width 속성 - 테두리우측두께 (= 테두리우측너비 = 테두리오른쪽너비 …
image CSS - Image Text - (이미지 위에 텍스트 배치/띄우기)
selector CSS - :disabled 가상선택자 - 비활성화 된 요소 선택 (= 실행불능요소 = 작동불능요소 = :d…
19/35
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티
웹유틸
회원센터
홈짱닷컴 PC버전 로그인