forked from Nish251103/web-portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
70 lines (51 loc) · 1.56 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
// typing texi effect
async function init () {
const node = document.querySelector("#type-text")
await sleep(1000)
node.innerText = ""
await node.type("I'm ")
while (true) {
await node.type("a Developer")
await sleep(2000)
await node.delete("a Developer")
await node.type("a Blogger")
await sleep(2000)
await node.delete("a Blogger")
await node.type("a Musician")
await sleep(2000)
await node.delete("a Musician")
}
}
const sleep = time => new Promise(resolve => setTimeout(resolve, time))
class TypeAsync extends HTMLSpanElement {
get typeInterval () {
const randomMs = 100 * Math.random()
return randomMs < 50 ? 10 : randomMs
}
async type (text) {
for (let character of text) {
this.innerText += character
await sleep(this.typeInterval)
}
}
async delete (text) {
for (let character of text) {
this.innerText = this.innerText.slice(0, this.innerText.length -1)
await sleep(this.typeInterval)
}
}
}
customElements.define('type-async', TypeAsync, { extends: 'span' })
var scrolBtn = document.querySelector("#myDIV");
window.addEventListener("scroll", function () {
let offset;
offset = window.pageYOffset;
if (offset > 300) {
scrolBtn.style.display = "block";
}
if (offset < 300) {
scrolBtn.style.display = "none";
}
});
init()
// .............................................................................................