-
Notifications
You must be signed in to change notification settings - Fork 0
/
hover.html
122 lines (96 loc) · 2.73 KB
/
hover.html
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
<html>
<head>
<title>HOVER Prototype</title>
<style>
body {
background: black;
}
.circle {
width: 400px;
height: 400px;
border-radius: 50%;
background: white;
opacity: 0.2;
position: fixed;
top: 0;
left: 0;
z-index: 999;
}
path {
fill: transparent;
transform-origin: center bottom;
transition: opacity 300ms ease-in-out, transform 300ms ease-in-out;
}
.invisible {
opacity: 0;
transform: scale(0);
}
</style>
</head>
<body>
<div class="trianglify"></div>
<div class="circle"></div>
<!-- JS -->
<script src="js/vendors/trianglify.min.js"></script>
<script>
window.onload = (function() {
// Create a new SVG pattern with Trianglify.
var pattern = Trianglify({
width: window.innerWidth,
height: window.innerHeight,
cell_size: 80,
variance: 1,
stroke_width: 1
}).svg(); // Render as SVG.
// Add pattern to DOM.
var container = document.querySelector('.trianglify');
container.insertBefore(pattern, container.firstChild);
// Get all pattern polygons.
var polyArray = [].slice.call(pattern.children);
// Get polygon coords and hide them.
var polyPoints = polyArray.map(function(poly) {
poly.classList.add('poly', 'invisible');
var rect = poly.getBoundingClientRect();
var point = {
x: rect.left + rect.width / 2,
y: rect.top + rect.height / 2
};
return point;
});
// Get circle for hover.
var circle = document.querySelector('.circle');
circle.addEventListener('mouseenter', function() {
document.addEventListener('mousemove', onMouseMove);
});
circle.addEventListener('mouseout', function() {
document.removeEventListener('mousemove', onMouseMove);
});
function onMouseMove(e) {
var radius = circle.clientWidth / 2;
var center = {
x: e.clientX,
y: e.clientY
};
circle.style.left = center.x - radius;
circle.style.top = center.y - radius;
polyPoints.forEach(function(point, i) {
if (detectPointInCircle(point, radius, center)) {
polyArray[i].classList.remove('invisible');
} else {
polyArray[i].classList.add('invisible');
}
});
};
function detectPointInCircle(point, radius, center) {
var xp = point.x;
var yp = point.y;
var xc = center.x;
var yc = center.y;
var d = radius * radius;
var isInside = Math.pow(xp - xc, 2) + Math.pow(yp - yc, 2) <= d;
return isInside;
};
});
</script>
</body>
</html>