-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyscripts.js
More file actions
48 lines (37 loc) · 1.17 KB
/
myscripts.js
File metadata and controls
48 lines (37 loc) · 1.17 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
console.log("Hello World!");
const blob = document.getElementById("blob");
/* First attempt at following the mouse in Javascript. This works, but the circle does not stay centered on the mouse.*/
document.body.onpointermove = event => {
const { clientX, clientY } = event;
blob.animate({
left: `${clientX}px`,
top: `${clientY}px`
}, {duration:3000, fill: "forwards"});
};
/*
const onMouseMove = (e) => {
blob.style.left = e.pageX + 'px';
blob.style.top = e.pageY + 'px';
}
*/
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let interval = null;
document.querySelector("h1").onmouseover = event => {
let iteration = 0;
clearInterval(interval);
interval = setInterval(() => {
event.target.innerText = event.target.innerText
.split("")
.map((letter, index) => {
if(index < iteration) {
return event.target.dataset.value[index];
}
return letters[Math.floor(Math.random() * 26)]
})
.join("");
if(iteration >= event.target.dataset.value.length){
clearInterval(interval);
}
iteration += 1 / 3;
}, 30);
}