-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
96 lines (79 loc) · 2.68 KB
/
main.js
File metadata and controls
96 lines (79 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(function () {
const win = window
const doc = document.documentElement
doc.classList.remove('no-js')
doc.classList.add('js')
// Reveal animations
if (document.body.classList.contains('has-animations')) {
/* global ScrollReveal */
const sr = window.sr = ScrollReveal()
sr.reveal('.hero-title, .hero-paragraph, .hero-form', {
duration: 1000,
distance: '40px',
easing: 'cubic-bezier(0.5, -0.01, 0, 1.005)',
origin: 'bottom',
interval: 150
})
}
// Moving objects
const movingObjects = document.querySelectorAll('.is-moving-object')
// Throttling
function throttle (func, milliseconds) {
let lastEventTimestamp = null
let limit = milliseconds
return (...args) => {
let now = Date.now()
if (!lastEventTimestamp || now - lastEventTimestamp >= limit) {
lastEventTimestamp = now
func.apply(this, args)
}
}
}
// Init vars
let mouseX = 0
let mouseY = 0
let scrollY = 0
let coordinateX = 0
let coordinateY = 0
let winW = doc.clientWidth
let winH = doc.clientHeight
// Move Objects
function moveObjects (e, object) {
mouseX = e.pageX
mouseY = e.pageY
scrollY = win.scrollY
coordinateX = (winW / 2) - mouseX
coordinateY = (winH / 2) - (mouseY - scrollY)
for (let i = 0; i < object.length; i++) {
const translatingFactor = object[i].getAttribute('data-translating-factor') || 20
const rotatingFactor = object[i].getAttribute('data-rotating-factor') || 20
const perspective = object[i].getAttribute('data-perspective') || 500
let tranformProperty = []
if (object[i].classList.contains('is-translating')) {
tranformProperty.push('translate(' + coordinateX / translatingFactor + 'px, ' + coordinateY / translatingFactor + 'px)')
}
if (object[i].classList.contains('is-rotating')) {
tranformProperty.push('perspective(' + perspective + 'px) rotateY(' + -coordinateX / rotatingFactor + 'deg) rotateX(' + coordinateY / rotatingFactor + 'deg)')
}
if (object[i].classList.contains('is-translating') || object[i].classList.contains('is-rotating')) {
tranformProperty = tranformProperty.join(' ')
object[i].style.transform = tranformProperty
object[i].style.transition = 'transform 1s ease-out'
object[i].style.transformStyle = 'preserve-3d'
object[i].style.backfaceVisibility = 'hidden'
}
}
}
// Call function with throttling
if (movingObjects) {
win.addEventListener('mousemove', throttle(
function (e) {
moveObjects(e, movingObjects)
},
150
))
}
}())
function notifyBuyButtonClicked(){
gtag('event', 'buy_clicked', {});
}