-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcursor.js
49 lines (43 loc) · 1.41 KB
/
cursor.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
let cursor = document.querySelector('.cursor');
let blob = document.querySelector('.blob');
let planet = document.querySelector('.solar-system .planet');
let author = document.querySelector('.author');
let footer = document.querySelector('.footer');
let links = document.querySelectorAll('a');
window.addEventListener('mousemove', function(e) {
cursor.animate({
top:e.pageY + 'px',
left:e.pageX + 'px'
}, {duration:1000, fill:'forwards'});
blob.animate({
top:e.pageY + 'px',
left:e.pageX + 'px'
}, {duration:7000, fill:'forwards'});
});
window.addEventListener('mousemove', function(e) {
bg_left = e.pageX/300;
bg_top = e.pageY/300;
planet.style.backgroundPosition = bg_left + '% ' + bg_top + '%';
});
window.addEventListener('scroll', function() {
if (author.getBoundingClientRect().top < (window.innerHeight)) {
blob.classList.add('author-color');
}
else {
blob.classList.remove('author-color');
}
if (footer.getBoundingClientRect().top < (window.innerHeight/10)) {
blob.style.display = 'none';
}
else {
blob.style.display = 'block';
}
});
links.forEach(link => {
link.addEventListener('mouseenter', (e) => {
cursor.style.opacity = 0;
})
link.addEventListener('mouseleave', (e) => {
cursor.style.opacity = 1;
})
});