-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
94 lines (83 loc) · 3.17 KB
/
index.js
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
document.addEventListener('DOMContentLoaded', e => {
let cardsContainer = document.querySelector('.header')
if (cardsContainer.offsetWidth >= 768) {
let cards = cardsContainer.querySelectorAll('.card3d')
cards.forEach(card => {
let plane = card.querySelector('.card3d-plane')
let glare = card.querySelector('.card3d-glare')
cardsContainer.addEventListener('mousemove', e => {
let {
left,
right,
top,
bottom,
height,
width
} = plane.getBoundingClientRect()
let centerX = right - width / 2
let centerY = bottom - height / 2
plane.style.transform = `
rotateX(${-15 * (e.pageY - centerY) / cardsContainer.offsetHeight}deg)
rotateY(${25 * (e.pageX - centerX) / cardsContainer.offsetWidth}deg)`
glare.style.transform = `
translateX(${-130 * e.pageX / cardsContainer.offsetWidth}px)
translateY(${-250 * e.pageY / cardsContainer.offsetHeight}px)`
})
let id
let tran = 50
cardsContainer.addEventListener('mouseenter', e => {
id = setInterval(() => {
if (tran <= 50) {
clearInterval(id)
} else {
tran -= 6
plane.style.transition = `transform ${tran}ms`
}
}, 16)
})
cardsContainer.addEventListener('mouseleave', e => {
if (id) clearInterval(id)
tran = 500
plane.style.transition = `transform ${tran}ms`
plane.style.transform = ''
})
})
}
let slidesContainers = document.querySelectorAll('.slides a')
Array.from(slidesContainers).map(loadSlides)
function loadSlides(slidesContainer, index) {
let xhr = new XMLHttpRequest()
xhr.open('GET', slidesContainer.href, true)
xhr.responseType = 'document'
xhr.onload = function () {
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 200) {
showSlides(slidesContainer, index, xhr.responseXML)
}
}
}
xhr.send(null)
}
function showSlides(slidesContainer, index, dom) {
let slides = Array.from(dom.images).map(i => {
let img = document.createElement('img')
img.className = "slide"
img.src = i.src
slidesContainer.appendChild(img)
return img
})
let next = 0
slides[next].classList.toggle("visible-slide")
setTimeout(showNextSlide, index * 2500 + 5000)
function showNextSlide() {
let prev = slides[next]
setTimeout(() => {
prev.classList.toggle("visible-slide")
}, 2000)
next++
if (next == slides.length) next = 0
slides[next].classList.toggle("visible-slide")
setTimeout(showNextSlide, 5000)
}
}
})