EddyCode commited on
Commit
9f7168c
·
1 Parent(s): b4364dc

Upload 3 files

Browse files
Files changed (3) hide show
  1. index.html +45 -0
  2. style.css +115 -0
  3. vanilla-tilt.js +512 -0
index.html ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Background Animation</title>
8
+ <link rel="stylesheet" href="style.css">
9
+
10
+
11
+ </head>
12
+ <body>
13
+ <div class="container">
14
+ <form class="calculator" name="calc">
15
+ <input type="text" readonly class="value" name="txt"/>
16
+ <span class="num clear" onclick="calc.txt.value=''">c</span>
17
+ <span class="num" onclick="document.calc.txt.value +='/'">/</span>
18
+ <span class="num" onclick="document.calc.txt.value +='*'">*</span>
19
+ <span class="num" onclick="document.calc.txt.value +='7'">7</span>
20
+ <span class="num" onclick="document.calc.txt.value +='8'">8</span>
21
+ <span class="num" onclick="document.calc.txt.value +='9'">9</span>
22
+ <span class="num" onclick="document.calc.txt.value +='-'">-</span>
23
+ <span class="num" onclick="document.calc.txt.value +='4'">4</span>
24
+ <span class="num" onclick="document.calc.txt.value +='5'">5</span>
25
+ <span class="num" onclick="document.calc.txt.value +='6'">6</span>
26
+ <span class="num plus" onclick="document.calc.txt.value +='+'">+</span>
27
+ <span class="num" onclick="document.calc.txt.value +='1'">1</span>
28
+ <span class="num" onclick="document.calc.txt.value +='2'">2</span>
29
+ <span class="num" onclick="document.calc.txt.value +='3'">3</span>
30
+ <span class="num" onclick="document.calc.txt.value +='0'">0</span>
31
+ <span class="num" onclick="document.calc.txt.value +='00'">00</span>
32
+ <span class="num" onclick="document.calc.txt.value +='.'">.</span>
33
+ <span class="num equal" onclick="document.calc.txt.value =eval(calc.txt.value)">=</span>
34
+ </form>
35
+ </div>
36
+ <script type="text/javascript" src="vanilla-tilt.js"></script>
37
+ <script type="text/javascript">
38
+ VanillaTilt.init(document.querySelector(".container"), {
39
+ max: 25,
40
+ speed: 400,
41
+ glare:true,
42
+ "max-glare":0.2,
43
+ });</script>
44
+ </body>
45
+ </html>
style.css ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@300;400;500&display=swap');
2
+
3
+
4
+ *{
5
+ margin: 0;
6
+ padding: 0;
7
+ box-sizing: border-box;
8
+ font-family: 'Quicksand',sans-serif;
9
+ }
10
+
11
+ body{
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ min-height: 100vh;
16
+ background: #091921;
17
+ }
18
+
19
+ body::before{
20
+ content: '';
21
+ position: absolute;
22
+ top: 0;
23
+ left: 0;
24
+ width: 100%;
25
+ height: 100%;
26
+ background: linear-gradient(#e91e63,#ffc107);
27
+ clip-path: circle(22% at 30% 20%);
28
+ }
29
+
30
+ body::after{
31
+ content: '';
32
+ position: absolute;
33
+ top: 0;
34
+ left: 0;
35
+ width: 100%;
36
+ height: 100%;
37
+ background: linear-gradient(#ffffff,#da00ff);
38
+ clip-path: circle(20% at 70% 90%);
39
+ }
40
+
41
+ .container{
42
+ position: relative;
43
+ background: rgba(255,255,255,0.05);
44
+ border-radius: 6px;
45
+ overflow: hidden;
46
+ z-index: 10;
47
+ backdrop-filter: blur(15px);
48
+ border-top: 1px solid rgba(255,255,255,0.2);
49
+ border-left: 1px solid rgba(255,255,255,0.2);
50
+ box-shadow: 5px 5px 30px rgba(0,0,0,0.2);
51
+ }
52
+
53
+ .container .calculator{
54
+ position: relative;
55
+ display: grid;
56
+ }
57
+
58
+ .container .calculator .value{
59
+ grid-column: span 4;
60
+ height: 140px;
61
+ width:300px;
62
+ text-align:right;
63
+ border:none;
64
+ outline:none;
65
+ padding: 10px;
66
+ font-size: 30px;
67
+ background:transparent;
68
+ color: #fff;
69
+
70
+ border-bottom: 1px solid rgba(255,255,255,0.05);
71
+ border-right: 1px solid rgba(255,255,255,0.05);
72
+ }
73
+
74
+ .container .calculator span{
75
+ display: grid;
76
+ place-items:center;
77
+ height:75px;
78
+ width:75px;
79
+ color:#fff;
80
+ font-weight: 400px;
81
+ cursor:pointer;
82
+ font-size:20px;
83
+ user-select:none;
84
+
85
+ border-bottom: 1px solid rgba(255,255,255,0.05);
86
+ border-right: 1px solid rgba(255,255,255,0.05);
87
+ transition: 0.5s
88
+ }
89
+
90
+ .container .calculator span:hover{
91
+ transition:0s;
92
+ background:rgba(255,255,255,0.05)
93
+ }
94
+
95
+ .container .calculator span:active{
96
+ background:#14ff47;
97
+ color: #192f00;
98
+ font-size:24px;
99
+ font-weight:500;
100
+ }
101
+
102
+ .container .calculator .clear{
103
+ grid-column: span 2;
104
+ width:150px;
105
+ background: rgba(255,255,255,0.05);
106
+ }
107
+
108
+ .container .calculator .plus{
109
+ grid-row: span 2;
110
+ height:150px;
111
+ }
112
+
113
+ .equal{
114
+ background: rgba(255,255,255,0.05);
115
+ }
vanilla-tilt.js ADDED
@@ -0,0 +1,512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var VanillaTilt = (function () {
2
+ 'use strict';
3
+
4
+ /**
5
+ * Created by Sergiu Șandor (micku7zu) on 1/27/2017.
6
+ * Original idea: https://github.com/gijsroge/tilt.js
7
+ * MIT License.
8
+ * Version 1.7.3
9
+ */
10
+
11
+ class VanillaTilt {
12
+ constructor(element, settings = {}) {
13
+ if (!(element instanceof Node)) {
14
+ throw ("Can't initialize VanillaTilt because " + element + " is not a Node.");
15
+ }
16
+
17
+ this.width = null;
18
+ this.height = null;
19
+ this.clientWidth = null;
20
+ this.clientHeight = null;
21
+ this.left = null;
22
+ this.top = null;
23
+
24
+ // for Gyroscope sampling
25
+ this.gammazero = null;
26
+ this.betazero = null;
27
+ this.lastgammazero = null;
28
+ this.lastbetazero = null;
29
+
30
+ this.transitionTimeout = null;
31
+ this.updateCall = null;
32
+ this.event = null;
33
+
34
+ this.updateBind = this.update.bind(this);
35
+ this.resetBind = this.reset.bind(this);
36
+
37
+ this.element = element;
38
+ this.settings = this.extendSettings(settings);
39
+
40
+ this.reverse = this.settings.reverse ? -1 : 1;
41
+ this.glare = VanillaTilt.isSettingTrue(this.settings.glare);
42
+ this.glarePrerender = VanillaTilt.isSettingTrue(this.settings["glare-prerender"]);
43
+ this.fullPageListening = VanillaTilt.isSettingTrue(this.settings["full-page-listening"]);
44
+ this.gyroscope = VanillaTilt.isSettingTrue(this.settings.gyroscope);
45
+ this.gyroscopeSamples = this.settings.gyroscopeSamples;
46
+
47
+ this.elementListener = this.getElementListener();
48
+
49
+ if (this.glare) {
50
+ this.prepareGlare();
51
+ }
52
+
53
+ if (this.fullPageListening) {
54
+ this.updateClientSize();
55
+ }
56
+
57
+ this.addEventListeners();
58
+ this.reset();
59
+ this.updateInitialPosition();
60
+ }
61
+
62
+ static isSettingTrue(setting) {
63
+ return setting === "" || setting === true || setting === 1;
64
+ }
65
+
66
+ /**
67
+ * Method returns element what will be listen mouse events
68
+ * @return {Node}
69
+ */
70
+ getElementListener() {
71
+ if (this.fullPageListening) {
72
+ return window.document;
73
+ }
74
+
75
+ if (typeof this.settings["mouse-event-element"] === "string") {
76
+ const mouseEventElement = document.querySelector(this.settings["mouse-event-element"]);
77
+
78
+ if (mouseEventElement) {
79
+ return mouseEventElement;
80
+ }
81
+ }
82
+
83
+ if (this.settings["mouse-event-element"] instanceof Node) {
84
+ return this.settings["mouse-event-element"];
85
+ }
86
+
87
+ return this.element;
88
+ }
89
+
90
+ /**
91
+ * Method set listen methods for this.elementListener
92
+ * @return {Node}
93
+ */
94
+ addEventListeners() {
95
+ this.onMouseEnterBind = this.onMouseEnter.bind(this);
96
+ this.onMouseMoveBind = this.onMouseMove.bind(this);
97
+ this.onMouseLeaveBind = this.onMouseLeave.bind(this);
98
+ this.onWindowResizeBind = this.onWindowResize.bind(this);
99
+ this.onDeviceOrientationBind = this.onDeviceOrientation.bind(this);
100
+
101
+ this.elementListener.addEventListener("mouseenter", this.onMouseEnterBind);
102
+ this.elementListener.addEventListener("mouseleave", this.onMouseLeaveBind);
103
+ this.elementListener.addEventListener("mousemove", this.onMouseMoveBind);
104
+
105
+ if (this.glare || this.fullPageListening) {
106
+ window.addEventListener("resize", this.onWindowResizeBind);
107
+ }
108
+
109
+ if (this.gyroscope) {
110
+ window.addEventListener("deviceorientation", this.onDeviceOrientationBind);
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Method remove event listeners from current this.elementListener
116
+ */
117
+ removeEventListeners() {
118
+ this.elementListener.removeEventListener("mouseenter", this.onMouseEnterBind);
119
+ this.elementListener.removeEventListener("mouseleave", this.onMouseLeaveBind);
120
+ this.elementListener.removeEventListener("mousemove", this.onMouseMoveBind);
121
+
122
+ if (this.gyroscope) {
123
+ window.removeEventListener("deviceorientation", this.onDeviceOrientationBind);
124
+ }
125
+
126
+ if (this.glare || this.fullPageListening) {
127
+ window.removeEventListener("resize", this.onWindowResizeBind);
128
+ }
129
+ }
130
+
131
+ destroy() {
132
+ clearTimeout(this.transitionTimeout);
133
+ if (this.updateCall !== null) {
134
+ cancelAnimationFrame(this.updateCall);
135
+ }
136
+
137
+ this.reset();
138
+
139
+ this.removeEventListeners();
140
+ this.element.vanillaTilt = null;
141
+ delete this.element.vanillaTilt;
142
+
143
+ this.element = null;
144
+ }
145
+
146
+ onDeviceOrientation(event) {
147
+ if (event.gamma === null || event.beta === null) {
148
+ return;
149
+ }
150
+
151
+ this.updateElementPosition();
152
+
153
+ if (this.gyroscopeSamples > 0) {
154
+ this.lastgammazero = this.gammazero;
155
+ this.lastbetazero = this.betazero;
156
+
157
+ if (this.gammazero === null) {
158
+ this.gammazero = event.gamma;
159
+ this.betazero = event.beta;
160
+ } else {
161
+ this.gammazero = (event.gamma + this.lastgammazero) / 2;
162
+ this.betazero = (event.beta + this.lastbetazero) / 2;
163
+ }
164
+
165
+ this.gyroscopeSamples -= 1;
166
+ }
167
+
168
+ const totalAngleX = this.settings.gyroscopeMaxAngleX - this.settings.gyroscopeMinAngleX;
169
+ const totalAngleY = this.settings.gyroscopeMaxAngleY - this.settings.gyroscopeMinAngleY;
170
+
171
+ const degreesPerPixelX = totalAngleX / this.width;
172
+ const degreesPerPixelY = totalAngleY / this.height;
173
+
174
+ const angleX = event.gamma - (this.settings.gyroscopeMinAngleX + this.gammazero);
175
+ const angleY = event.beta - (this.settings.gyroscopeMinAngleY + this.betazero);
176
+
177
+ const posX = angleX / degreesPerPixelX;
178
+ const posY = angleY / degreesPerPixelY;
179
+
180
+ if (this.updateCall !== null) {
181
+ cancelAnimationFrame(this.updateCall);
182
+ }
183
+
184
+ this.event = {
185
+ clientX: posX + this.left,
186
+ clientY: posY + this.top,
187
+ };
188
+
189
+ this.updateCall = requestAnimationFrame(this.updateBind);
190
+ }
191
+
192
+ onMouseEnter() {
193
+ this.updateElementPosition();
194
+ this.element.style.willChange = "transform";
195
+ this.setTransition();
196
+ }
197
+
198
+ onMouseMove(event) {
199
+ if (this.updateCall !== null) {
200
+ cancelAnimationFrame(this.updateCall);
201
+ }
202
+
203
+ this.event = event;
204
+ this.updateCall = requestAnimationFrame(this.updateBind);
205
+ }
206
+
207
+ onMouseLeave() {
208
+ this.setTransition();
209
+
210
+ if (this.settings.reset) {
211
+ requestAnimationFrame(this.resetBind);
212
+ }
213
+ }
214
+
215
+ reset() {
216
+ this.event = {
217
+ clientX: this.left + this.width / 2,
218
+ clientY: this.top + this.height / 2
219
+ };
220
+
221
+ if (this.element && this.element.style) {
222
+ this.element.style.transform = `perspective(${this.settings.perspective}px) ` +
223
+ `rotateX(0deg) ` +
224
+ `rotateY(0deg) ` +
225
+ `scale3d(1, 1, 1)`;
226
+ }
227
+
228
+ this.resetGlare();
229
+ }
230
+
231
+ resetGlare() {
232
+ if (this.glare) {
233
+ this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
234
+ this.glareElement.style.opacity = "0";
235
+ }
236
+ }
237
+
238
+ updateInitialPosition() {
239
+ if (this.settings.startX === 0 && this.settings.startY === 0) {
240
+ return;
241
+ }
242
+
243
+ this.onMouseEnter();
244
+
245
+ if (this.fullPageListening) {
246
+ this.event = {
247
+ clientX: (this.settings.startX + this.settings.max) / (2 * this.settings.max) * this.clientWidth,
248
+ clientY: (this.settings.startY + this.settings.max) / (2 * this.settings.max) * this.clientHeight
249
+ };
250
+ } else {
251
+ this.event = {
252
+ clientX: this.left + ((this.settings.startX + this.settings.max) / (2 * this.settings.max) * this.width),
253
+ clientY: this.top + ((this.settings.startY + this.settings.max) / (2 * this.settings.max) * this.height)
254
+ };
255
+ }
256
+
257
+
258
+ let backupScale = this.settings.scale;
259
+ this.settings.scale = 1;
260
+ this.update();
261
+ this.settings.scale = backupScale;
262
+ this.resetGlare();
263
+ }
264
+
265
+ getValues() {
266
+ let x, y;
267
+
268
+ if (this.fullPageListening) {
269
+ x = this.event.clientX / this.clientWidth;
270
+ y = this.event.clientY / this.clientHeight;
271
+ } else {
272
+ x = (this.event.clientX - this.left) / this.width;
273
+ y = (this.event.clientY - this.top) / this.height;
274
+ }
275
+
276
+ x = Math.min(Math.max(x, 0), 1);
277
+ y = Math.min(Math.max(y, 0), 1);
278
+
279
+ let tiltX = (this.reverse * (this.settings.max - x * this.settings.max * 2)).toFixed(2);
280
+ let tiltY = (this.reverse * (y * this.settings.max * 2 - this.settings.max)).toFixed(2);
281
+ let angle = Math.atan2(this.event.clientX - (this.left + this.width / 2), -(this.event.clientY - (this.top + this.height / 2))) * (180 / Math.PI);
282
+
283
+ return {
284
+ tiltX: tiltX,
285
+ tiltY: tiltY,
286
+ percentageX: x * 100,
287
+ percentageY: y * 100,
288
+ angle: angle
289
+ };
290
+ }
291
+
292
+ updateElementPosition() {
293
+ let rect = this.element.getBoundingClientRect();
294
+
295
+ this.width = this.element.offsetWidth;
296
+ this.height = this.element.offsetHeight;
297
+ this.left = rect.left;
298
+ this.top = rect.top;
299
+ }
300
+
301
+ update() {
302
+ let values = this.getValues();
303
+
304
+ this.element.style.transform = "perspective(" + this.settings.perspective + "px) " +
305
+ "rotateX(" + (this.settings.axis === "x" ? 0 : values.tiltY) + "deg) " +
306
+ "rotateY(" + (this.settings.axis === "y" ? 0 : values.tiltX) + "deg) " +
307
+ "scale3d(" + this.settings.scale + ", " + this.settings.scale + ", " + this.settings.scale + ")";
308
+
309
+ if (this.glare) {
310
+ this.glareElement.style.transform = `rotate(${values.angle}deg) translate(-50%, -50%)`;
311
+ this.glareElement.style.opacity = `${values.percentageY * this.settings["max-glare"] / 100}`;
312
+ }
313
+
314
+ this.element.dispatchEvent(new CustomEvent("tiltChange", {
315
+ "detail": values
316
+ }));
317
+
318
+ this.updateCall = null;
319
+ }
320
+
321
+ /**
322
+ * Appends the glare element (if glarePrerender equals false)
323
+ * and sets the default style
324
+ */
325
+ prepareGlare() {
326
+ // If option pre-render is enabled we assume all html/css is present for an optimal glare effect.
327
+ if (!this.glarePrerender) {
328
+ // Create glare element
329
+ const jsTiltGlare = document.createElement("div");
330
+ jsTiltGlare.classList.add("js-tilt-glare");
331
+
332
+ const jsTiltGlareInner = document.createElement("div");
333
+ jsTiltGlareInner.classList.add("js-tilt-glare-inner");
334
+
335
+ jsTiltGlare.appendChild(jsTiltGlareInner);
336
+ this.element.appendChild(jsTiltGlare);
337
+ }
338
+
339
+ this.glareElementWrapper = this.element.querySelector(".js-tilt-glare");
340
+ this.glareElement = this.element.querySelector(".js-tilt-glare-inner");
341
+
342
+ if (this.glarePrerender) {
343
+ return;
344
+ }
345
+
346
+ Object.assign(this.glareElementWrapper.style, {
347
+ "position": "absolute",
348
+ "top": "0",
349
+ "left": "0",
350
+ "width": "100%",
351
+ "height": "100%",
352
+ "overflow": "hidden",
353
+ "pointer-events": "none",
354
+ "border-radius": "inherit",
355
+ });
356
+
357
+ Object.assign(this.glareElement.style, {
358
+ "position": "absolute",
359
+ "top": "50%",
360
+ "left": "50%",
361
+ "pointer-events": "none",
362
+ "background-image": `linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%)`,
363
+ "transform": "rotate(180deg) translate(-50%, -50%)",
364
+ "transform-origin": "0% 0%",
365
+ "opacity": "0",
366
+ });
367
+
368
+ this.updateGlareSize();
369
+ }
370
+
371
+ updateGlareSize() {
372
+ if (this.glare) {
373
+ const glareSize = (this.element.offsetWidth > this.element.offsetHeight ? this.element.offsetWidth : this.element.offsetHeight) * 2;
374
+
375
+ Object.assign(this.glareElement.style, {
376
+ "width": `${glareSize}px`,
377
+ "height": `${glareSize}px`,
378
+ });
379
+ }
380
+ }
381
+
382
+ updateClientSize() {
383
+ this.clientWidth = window.innerWidth
384
+ || document.documentElement.clientWidth
385
+ || document.body.clientWidth;
386
+
387
+ this.clientHeight = window.innerHeight
388
+ || document.documentElement.clientHeight
389
+ || document.body.clientHeight;
390
+ }
391
+
392
+ onWindowResize() {
393
+ this.updateGlareSize();
394
+ this.updateClientSize();
395
+ }
396
+
397
+ setTransition() {
398
+ clearTimeout(this.transitionTimeout);
399
+ this.element.style.transition = this.settings.speed + "ms " + this.settings.easing;
400
+ if (this.glare) this.glareElement.style.transition = `opacity ${this.settings.speed}ms ${this.settings.easing}`;
401
+
402
+ this.transitionTimeout = setTimeout(() => {
403
+ this.element.style.transition = "";
404
+ if (this.glare) {
405
+ this.glareElement.style.transition = "";
406
+ }
407
+ }, this.settings.speed);
408
+
409
+ }
410
+
411
+ /**
412
+ * Method return patched settings of instance
413
+ * @param {boolean} settings.reverse - reverse the tilt direction
414
+ * @param {number} settings.max - max tilt rotation (degrees)
415
+ * @param {startX} settings.startX - the starting tilt on the X axis, in degrees. Default: 0
416
+ * @param {startY} settings.startY - the starting tilt on the Y axis, in degrees. Default: 0
417
+ * @param {number} settings.perspective - Transform perspective, the lower the more extreme the tilt gets
418
+ * @param {string} settings.easing - Easing on enter/exit
419
+ * @param {number} settings.scale - 2 = 200%, 1.5 = 150%, etc..
420
+ * @param {number} settings.speed - Speed of the enter/exit transition
421
+ * @param {boolean} settings.transition - Set a transition on enter/exit
422
+ * @param {string|null} settings.axis - What axis should be enabled. Can be "x" or "y"
423
+ * @param {boolean} settings.glare - if it should have a "glare" effect
424
+ * @param {number} settings.max-glare - the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
425
+ * @param {boolean} settings.glare-prerender - false = VanillaTilt creates the glare elements for you, otherwise
426
+ * @param {boolean} settings.full-page-listening - If true, parallax effect will listen to mouse move events on the whole document, not only the selected element
427
+ * @param {string|object} settings.mouse-event-element - String selector or link to HTML-element what will be listen mouse events
428
+ * @param {boolean} settings.reset - false = If the tilt effect has to be reset on exit
429
+ * @param {gyroscope} settings.gyroscope - Enable tilting by deviceorientation events
430
+ * @param {gyroscopeSensitivity} settings.gyroscopeSensitivity - Between 0 and 1 - The angle at which max tilt position is reached. 1 = 90deg, 0.5 = 45deg, etc..
431
+ * @param {gyroscopeSamples} settings.gyroscopeSamples - How many gyroscope moves to decide the starting position.
432
+ */
433
+ extendSettings(settings) {
434
+ let defaultSettings = {
435
+ reverse: false,
436
+ max: 15,
437
+ startX: 0,
438
+ startY: 0,
439
+ perspective: 1000,
440
+ easing: "cubic-bezier(.03,.98,.52,.99)",
441
+ scale: 1,
442
+ speed: 300,
443
+ transition: true,
444
+ axis: null,
445
+ glare: false,
446
+ "max-glare": 1,
447
+ "glare-prerender": false,
448
+ "full-page-listening": false,
449
+ "mouse-event-element": null,
450
+ reset: true,
451
+ gyroscope: true,
452
+ gyroscopeMinAngleX: -45,
453
+ gyroscopeMaxAngleX: 45,
454
+ gyroscopeMinAngleY: -45,
455
+ gyroscopeMaxAngleY: 45,
456
+ gyroscopeSamples: 10
457
+ };
458
+
459
+ let newSettings = {};
460
+ for (var property in defaultSettings) {
461
+ if (property in settings) {
462
+ newSettings[property] = settings[property];
463
+ } else if (this.element.hasAttribute("data-tilt-" + property)) {
464
+ let attribute = this.element.getAttribute("data-tilt-" + property);
465
+ try {
466
+ newSettings[property] = JSON.parse(attribute);
467
+ } catch (e) {
468
+ newSettings[property] = attribute;
469
+ }
470
+
471
+ } else {
472
+ newSettings[property] = defaultSettings[property];
473
+ }
474
+ }
475
+
476
+ return newSettings;
477
+ }
478
+
479
+ static init(elements, settings) {
480
+ if (elements instanceof Node) {
481
+ elements = [elements];
482
+ }
483
+
484
+ if (elements instanceof NodeList) {
485
+ elements = [].slice.call(elements);
486
+ }
487
+
488
+ if (!(elements instanceof Array)) {
489
+ return;
490
+ }
491
+
492
+ elements.forEach((element) => {
493
+ if (!("vanillaTilt" in element)) {
494
+ element.vanillaTilt = new VanillaTilt(element, settings);
495
+ }
496
+ });
497
+ }
498
+ }
499
+
500
+ if (typeof document !== "undefined") {
501
+ /* expose the class to window */
502
+ window.VanillaTilt = VanillaTilt;
503
+
504
+ /**
505
+ * Auto load
506
+ */
507
+ VanillaTilt.init(document.querySelectorAll("[data-tilt]"));
508
+ }
509
+
510
+ return VanillaTilt;
511
+
512
+ }());