-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
122 lines (116 loc) · 6.04 KB
/
index.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
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>LR</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.616;
margin: 0;
min-height: 100vh;
min-width: 100vw;
padding: 0;
}
.container {
align-items: center;
background-color: #fff;
color: #3f3f3f;
display: flex;
justify-content: center;
min-height: 100vh;
}
h1 {
font-size: 3em;
letter-spacing: 1.25em;
margin-top: 0;
text-transform: uppercase;
padding-left: 1.25em;
filter: url(#filter);
}
svg {
opacity: 0;
position: absolute;
z-index: -1;
}
</style>
</head>
<body>
<svg>
<!-- v1 - the offset -->
<filter id="filter-v1" x="0%" y="0%" width="100%" height="100%" filterUnits="objectBoundingBox" primitiveUnits="userSpaceOnUse" color-interpolation-filters="linearRGB">
<feDropShadow stdDeviation="0 0" in="SourceGraphic" dx="13" dy="10" flood-color="#ff2600" flood-opacity="0.3" x="0%" y="0%" width="100%" height="100%" result="redChannel"/>
<feDropShadow stdDeviation="0 0" in="redChannel" dx="-5" dy="4" flood-color="#0432ff" flood-opacity="0.3" x="0%" y="0%" width="100%" height="100%" result="blueChannel"/>
</filter>
<!-- v2 - animate offset on hover -->
<filter id="filter-v2" x="0%" y="0%" width="100%" height="100%" filterUnits="objectBoundingBox" primitiveUnits="userSpaceOnUse" color-interpolation-filters="linearRGB">
<feDropShadow stdDeviation="0 0" in="SourceGraphic" dx="0" dy="0" flood-color="#ff2600" flood-opacity="0.3" x="0%" y="0%" width="100%" height="100%" result="redChannel">
<animate attributeName="dx" values="0;13" dur="200ms" begin="zapo.mouseenter" fill="freeze"/>
<animate attributeName="dy" values="0;10" dur="200ms" begin="zapo.mouseenter" fill="freeze"/>
</feDropShadow>
<feDropShadow stdDeviation="0 0" in="redChannel" dx="0" dy="0" flood-color="#0432ff" flood-opacity="0.3" x="0%" y="0%" width="100%" height="100%" result="blueChannel">
<animate attributeName="dx" values="0;-5" dur="200ms" begin="zapo.mouseenter" fill="freeze"/>
<animate attributeName="dy" values="0;4" dur="600ms" begin="zapo.mouseenter" fill="freeze"/>
</feDropShadow>
</filter>
<!-- v3 - animate offset on hover -->
<filter id="filter" x="0%" y="0%" width="100%" height="100%" filterUnits="objectBoundingBox" primitiveUnits="userSpaceOnUse" color-interpolation-filters="linearRGB">
<feDropShadow id="redOffset" stdDeviation="0 0" in="SourceGraphic" dx="0" dy="0" flood-color="#ff2600" flood-opacity="0.3" x="0%" y="0%" width="100%" height="100%" result="redChannel">
<animate attributeName="dx" values="0;13" dur="200ms" begin="zapo.mouseenter" fill="freeze"/>
<animate attributeName="dy" values="0;10" dur="200ms" begin="zapo.mouseenter" fill="freeze"/>
<animate attributeName="dx" values="13;0" dur="200ms" begin="zapo.mouseleave" fill="freeze"/>
<animate attributeName="dy" values="10;0" dur="200ms" begin="zapo.mouseleave" fill="freeze"/>
</feDropShadow>
<feDropShadow id="blueOffset" stdDeviation="0 0" in="redChannel" dx="0" dy="0" flood-color="#0432ff" flood-opacity="0.3" x="0%" y="0%" width="100%" height="100%" result="blueChannel">
<animate attributeName="dx" values="0;-5" dur="200ms" begin="zapo.mouseenter" fill="freeze"/>
<animate attributeName="dy" values="0;4" dur="600ms" begin="zapo.mouseenter" fill="freeze"/>
<animate attributeName="dx" values="-5;0" dur="200ms" begin="zapo.mouseleave" fill="freeze"/>
<animate attributeName="dy" values="4;0" dur="600ms" begin="zapo.mouseleave" fill="freeze"/>
</feDropShadow>
</filter>
</svg>
<div class="container">
<h1 id="zapo">Zapo</h1>
</div>
<script>
let redOffset = document.querySelector('#redOffset');
let blueOffset = document.querySelector('#blueOffset');
document.querySelector('#zapo').addEventListener('mouseleave', function() {
setTimeout(updateDXdYvalues, 250);
});
function updateDXdYvalues() {
// console.log('change dx, dy values');
// change red offset
let newOffset;
// get new red dx
newOffset = randomValue();
redOffset.querySelector('[attributeName="dx"][begin="zapo.mouseenter"]').setAttribute('values', `0; ${newOffset}`);
redOffset.querySelector('[attributeName="dx"][begin="zapo.mouseleave"]').setAttribute('values', `${newOffset}; 0`);
// get new red dy
newOffset = randomValue();
redOffset.querySelector('[attributeName="dy"][begin="zapo.mouseenter"]').setAttribute('values', `0; ${newOffset}`);
redOffset.querySelector('[attributeName="dy"][begin="zapo.mouseleave"]').setAttribute('values', `${newOffset}; 0`);
// get new blue dx
newOffset = randomValue();
blueOffset.querySelector('[attributeName="dx"][begin="zapo.mouseenter"]').setAttribute('values', `0; ${newOffset}`);
blueOffset.querySelector('[attributeName="dx"][begin="zapo.mouseleave"]').setAttribute('values', `${newOffset}; 0`);
// get new blue dy
newOffset = randomValue();
blueOffset.querySelector('[attributeName="dy"][begin="zapo.mouseenter"]').setAttribute('values', `0; ${newOffset}`);
blueOffset.querySelector('[attributeName="dy"][begin="zapo.mouseleave"]').setAttribute('values', `${newOffset}; 0`);
}
function randomValue() {
// from -5 to 13
return Math.floor((Math.random()*20) - (Math.random() * 20));
}
</script>
<!--
Sources
- https://yoksel.github.io/svg-filters/#/
- https://viewbox.club/tips/02.CSS_Filters.html
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/dx
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/begin
-->
</body>
</html>