:lab
코딩일기
:lab
전체 방문자
오늘
어제
  • 분류 전체보기 (28)
    • 일상 (5)
      • 과학 (0)
      • 개발 (1)
      • Apple (3)
      • 갤럭시 (1)
      • 기타 (0)
    • 실험실 (0)
    • 배운 것들 (17)
      • 블렌더 Blender (0)
      • 깃허브 Github (1)
      • html,css,js (7)
      • python (6)
      • React Native (1)
      • Unity (1)
      • 기타 (1)
    • 블로그 (6)
      • 꾸미기 (4)
      • 수익 (2)

블로그 메뉴

  • 🧇 홈
  • 🏷 태그
  • 🎒 방명록

공지사항

인기 글

태그

  • 브라우저
  • 텐핑
  • react native
  • vscode
  • 크롬
  • Github
  • kivy
  • tilt.js
  • PyAudio
  • 이게뭐여
  • LINK
  • pywebview
  • 파이썬
  • Ionicons
  • 클론 사이트
  • Android
  • lipsync
  • 티스토리
  • 폰트
  • 10ping
  • CSS
  • STANDWITHUKRAINE
  • h 태그
  • Python
  • alt-c
  • 안드로이드
  • HTML
  • ios
  • chrome
  • 광고
  • 왜 됐지
  • 수익
  • Prefix
  • Karabiner-Elements
  • 구글
  • 햄버거메뉴
  • 구글 클론 사이트
  • prefix free
  • tenping
  • font family
  • Mac
  • 이스터에그
  • Vendor Prefix
  • 카카오
  • 애드핏
  • 깃허브
  • 가상 램
  • 맥
  • Random.Range
  • RAM Plus

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
:lab

코딩일기

[JS] tilt.js 사용하기
배운 것들/html,css,js

[JS] tilt.js 사용하기

2021. 2. 22. 17:04
728x90

Vanilla-tilt.js 깃허브 Repo

 

micku7zu/vanilla-tilt.js

A smooth 3D tilt javascript library. Contribute to micku7zu/vanilla-tilt.js development by creating an account on GitHub.

github.com

 

tilt.js를 사용하면

html에 tilt 효과를 줄 수 있습니다.

 

설치

깃허브에서 직접 코드를 복사해 js파일을 만들어도 되고,

npm으로도 설치할 수 있다고 합니다.

npm install vanilla-tilt

(이 vanilla-tilt.js는 바닐라 스크립트(jQuery 이용 X, 순수한 자바스크립트)로 작성되었습니다.)

 

기본 사용

vanilla-tilt.js를 사용하려면 위에서 설치를 완료한 후,

<!-- at the end of the body -->
<script type="text/javascript" src="vanilla-tilt.js"></script>

이 코드를 html의 body 태그 가장 아래에 넣어주면 됩니다.

("이 코드는 vanilla-tilt.js를 불러오겠다"라는 의미입니다.)

(참고로 티스토리에선 따로 파일을 추가할 경우 images 폴더 안에 저장되기 때문에 src를./images/vanilla-tilt.js로 바꾸어주어야 합니다.)

 

이렇게 불러온 후,

원하는 개체에 tilt 효과를 적용해줍니다.

 

data-tilt 넣기

<div class="your-element" data-tilt></div>

JS 이용

<script type="text/javascript" src="vanilla-tilt.js"></script>
<script type="text/javascript">
	VanillaTilt.init(document.querySelector(".your-element"), {
		max: 25,
		speed: 400
	});
	
	//It also supports NodeList
	VanillaTilt.init(document.querySelectorAll(".your-element"));
</script>

 

이렇게 직접 개체 뒤에 data-tilt를 넣어주어도 되고,

자바스크립트를 작성해 vanilla-tilt.js 밑에 넣어 원하는 클래스의 개체에 적용시켜주는 방법도 있습니다.

 

속성 추가

• data-tilt를 사용한 경우

<div class="your-element" data-tilt data-tilt-max="50" data-tilt-speed="400" data-tilt-perspective="500"></div>

data-tilt를 넣은 경우에는 data-tilt 뒤에 data-tilt-max="50"과 같이 넣어주는 방법이 있습니다.

 

• JS로 적용시킨 경우

VanillaTilt.init(document.querySelector(".your-element"), {
	max: 25,
	speed: 400
});

이렇게 속성을 추가해 줄 수 있습니다.

 

• 기본값

{
    reverse:                false,  // reverse the tilt direction
    max:                    35,     // max tilt rotation (degrees)
    startX:                 0,      // the starting tilt on the X axis, in degrees.
    startY:                 0,      // the starting tilt on the Y axis, in degrees.
    perspective:            1000,   // Transform perspective, the lower the more extreme the tilt gets.
    scale:                  1,      // 2 = 200%, 1.5 = 150%, etc..
    speed:                  300,    // Speed of the enter/exit transition
    transition:             true,   // Set a transition on enter/exit.
    axis:                   null,   // What axis should be disabled. Can be X or Y.
    reset:                  true    // If the tilt effect has to be reset on exit.
    easing:                 "cubic-bezier(.03,.98,.52,.99)",    // Easing on enter/exit.
    glare:                  false   // if it should have a "glare" effect
    "max-glare":            1,      // the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
    "glare-prerender":      false,  // false = VanillaTilt creates the glare elements for you, otherwise
                                    // you need to add .js-tilt-glare>.js-tilt-glare-inner by yourself
    "mouse-event-element":  null    // css-selector or link to HTML-element what will be listen mouse events
                                    // you need to add .js-tilt-glare>.js-tilt-glare-inner by yourself
    gyroscope:              true    // Boolean to enable/disable device orientation detection,
    gyroscopeMinAngleX:     -45     // This is the bottom limit of the device angle on X axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the left border of the element;
    gyroscopeMaxAngleX:     45      // This is the top limit of the device angle on X axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the right border of the element;
    gyroscopeMinAngleY:     -45     // This is the bottom limit of the device angle on Y axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the top border of the element;
    gyroscopeMaxAngleY:     45      // This is the top limit of the device angle on Y axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the bottom border of the element;
}

 

 

예제 코드

 

728x90

'배운 것들 > html,css,js' 카테고리의 다른 글

[Chrome] 구글 크롬 공룡 게임 가지고 놀기 👾  (0) 2022.04.12
[CSS] -prefix-free 사용하기  (0) 2021.02.14
[CSS] Vendor Prefix란?  (0) 2021.02.14
[html] link의 종류  (0) 2021.02.07
h 태그란? (<h1>, <h2>, <h3>.....)  (0) 2021.02.01
    '배운 것들/html,css,js' 카테고리의 다른 글
    • [Chrome] 구글 크롬 공룡 게임 가지고 놀기 👾
    • [CSS] -prefix-free 사용하기
    • [CSS] Vendor Prefix란?
    • [html] link의 종류
    :lab
    :lab
    환영합니다! :D

    티스토리툴바