-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
133 lines (116 loc) · 3.5 KB
/
main.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const buttons = Array.from(document.querySelectorAll('.button'))
const contents = Array.from(document.querySelectorAll('.content'))
//Typewriter Effect
function setupTypewriter(t) {
var HTML = t.innerHTML
t.innerHTML = ''
var cursorPosition = 0,
tag = '',
writingTag = false,
tagOpen = false,
typeSpeed = 100,
tempTypeSpeed = 0
var type = function() {
if (writingTag === true) {
tag += HTML[cursorPosition]
}
if (HTML[cursorPosition] === '<') {
tempTypeSpeed = 0
if (tagOpen) {
tagOpen = false
writingTag = true
} else {
tag = ''
tagOpen = true
writingTag = true
tag += HTML[cursorPosition]
}
}
if (!writingTag && tagOpen) {
tag.innerHTML += HTML[cursorPosition]
}
if (!writingTag && !tagOpen) {
if (HTML[cursorPosition] === ' ') {
tempTypeSpeed = 0
} else {
tempTypeSpeed = Math.random() * typeSpeed + 50
}
t.innerHTML += HTML[cursorPosition]
}
if (writingTag === true && HTML[cursorPosition] === '>') {
tempTypeSpeed = Math.random() * typeSpeed + 50
writingTag = false
if (tagOpen) {
var newSpan = document.createElement('span')
t.appendChild(newSpan)
newSpan.innerHTML = tag
tag = newSpan.firstChild
}
}
cursorPosition += 1
if (cursorPosition < HTML.length - 1) {
setTimeout(type, tempTypeSpeed)
}
}
return {
type: type,
}
}
var typewriter = document.getElementById('typewriter')
typewriter = setupTypewriter(typewriter)
let x = true
buttons.forEach(btn => {
btn.addEventListener('click', () => {
if (btn.classList.contains('about') && x) {
typewriter.type()
x = false
}
buttons.forEach(b => {
b.classList.remove('buttonoff')
})
btn.classList.add('buttonoff')
const contentclass = btn.classList[1] + 'window'
contents.forEach(ctn => {
ctn.classList.add('contentoff')
ctn.classList.remove('contenton')
if (ctn.classList.contains(contentclass)) {
ctn.classList.remove('contentoff')
ctn.classList.add('contenton')
}
})
})
})
//Caraousel Effect
const carouselslide = document.querySelector('.slidecontainer')
const carouseldivs = Array.from(document.querySelectorAll('.carouseldiv'))
const workleft = document.querySelector('.workleft')
const workright = document.querySelector('.workright')
let counter = 1
const size = carouseldivs[0].clientWidth
carouselslide.style.transform = `translateX(${-size * counter}px)`
workright.addEventListener('click', () => {
if (counter >= carouseldivs.length - 1) return
carouselslide.style.transition =
'transform 2.2s cubic-bezier(1,-0.8,.02,1.71)'
counter++
carouselslide.style.transform = `translateX(${-size * counter}px)`
})
workleft.addEventListener('click', () => {
if (counter <= 0) return
carouselslide.style.transition =
'transform 2.2s cubic-bezier(1,-0.8,.02,1.71)'
counter--
carouselslide.style.transform = `translateX(${-size * counter}px)`
})
carouselslide.addEventListener('transitionend', () => {
if (carouseldivs[counter].id === 'lastclone') {
carouselslide.style.transition = 'none'
counter = carouseldivs.length - 2
carouselslide.style.transform = `translateX(${-size * counter}px)`
}
if (carouseldivs[counter].id === 'firstclone') {
carouselslide.style.transition = 'none'
counter = carouseldivs.length - counter
carouselslide.style.transform = `translateX(${-size * counter}px)`
}
})