mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-14 13:23:41 +02:00
Compare commits
1 commit
7ca70d7850
...
1c44354e5b
Author | SHA1 | Date | |
---|---|---|---|
1c44354e5b |
2 changed files with 25 additions and 21 deletions
|
@ -50,6 +50,8 @@ section.version {
|
||||||
/* # Interests */
|
/* # Interests */
|
||||||
|
|
||||||
div.interests {
|
div.interests {
|
||||||
|
--text-shadow-blur: 30px;
|
||||||
|
|
||||||
transition: 300ms opacity;
|
transition: 300ms opacity;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -58,7 +60,7 @@ div.interests {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
font-size: 50px;
|
font-size: clamp(16px, 15vw, 50px);
|
||||||
color: var(--color-accent);
|
color: var(--color-accent);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
@ -70,9 +72,7 @@ div.interests.active {
|
||||||
}
|
}
|
||||||
|
|
||||||
div.interests p {
|
div.interests p {
|
||||||
--text-shadow-blur: 30px;
|
transition: 500ms transform cubic-bezier(.34,0,0,.99);
|
||||||
|
|
||||||
transition: 300ms transform;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
text-shadow:
|
text-shadow:
|
||||||
0 0 var(--text-shadow-blur) black,
|
0 0 var(--text-shadow-blur) black,
|
||||||
|
|
|
@ -6,26 +6,35 @@ const randomIntFromInterval = (min, max) => {
|
||||||
|
|
||||||
// Interest explosion effect from origin position
|
// Interest explosion effect from origin position
|
||||||
const explodeInterests = (originX, originY) => {
|
const explodeInterests = (originX, originY) => {
|
||||||
// Elements can not translate more than negative- and positive from this number
|
|
||||||
const TRANS_LIMIT = 300;
|
|
||||||
|
|
||||||
const wrapper = document.querySelector("div.interests");
|
const wrapper = document.querySelector("div.interests");
|
||||||
wrapper.classList.add("active");
|
wrapper.classList.add("active");
|
||||||
|
|
||||||
|
// Elements can not expand further than positive or negative of these values
|
||||||
|
const transLimitX = window.innerWidth / 4;
|
||||||
|
const transLimitY = window.innerHeight / 3;
|
||||||
|
|
||||||
[...wrapper.querySelectorAll("p")].forEach(element => {
|
[...wrapper.querySelectorAll("p")].forEach(element => {
|
||||||
/*
|
const size = element.getBoundingClientRect();
|
||||||
Generate random visuals for current element
|
|
||||||
*/
|
// Generate random HUE wheel rotation degrees
|
||||||
const hue = randomIntFromInterval(0, 360);
|
const hue = randomIntFromInterval(0, 360);
|
||||||
|
// Generate random element transform rotation
|
||||||
const rotate = randomIntFromInterval(-5, 5);
|
const rotate = randomIntFromInterval(-5, 5);
|
||||||
const transX = randomIntFromInterval(TRANS_LIMIT * -1, TRANS_LIMIT);
|
|
||||||
const transY = randomIntFromInterval(TRANS_LIMIT * -1, TRANS_LIMIT);
|
// Generate random offsets in each direction clamped to translation limit
|
||||||
|
let transX = randomIntFromInterval(transLimitX * -1, transLimitX);
|
||||||
|
let transY = randomIntFromInterval(transLimitY * -1, transLimitY);
|
||||||
|
|
||||||
|
// Clamp translation to screen left and right X size
|
||||||
|
transX = Math.max(0 - originX, Math.min((window.innerWidth - originX) - size.width, transX));
|
||||||
|
// Clamp translation to top and bottom Y size
|
||||||
|
transY = Math.max(0 - originY, Math.min((window.innerHeight - originY) - size.height, transY));
|
||||||
|
|
||||||
// Set initial position
|
// Set initial position
|
||||||
element.style.setProperty("top", `${originY}px`);
|
element.style.setProperty("top", `${originY}px`);
|
||||||
element.style.setProperty("left", `${originX}px`);
|
element.style.setProperty("left", `${originX}px`);
|
||||||
|
|
||||||
// Set random HUE rotation
|
// Set HUE rotation
|
||||||
element.style.setProperty("-webkit-filter", `hue-rotate(${hue}deg)`);
|
element.style.setProperty("-webkit-filter", `hue-rotate(${hue}deg)`);
|
||||||
element.style.setProperty("filter", `hue-rotate(${hue}deg)`);
|
element.style.setProperty("filter", `hue-rotate(${hue}deg)`);
|
||||||
|
|
||||||
|
@ -39,10 +48,8 @@ const implodeInterests = () => {
|
||||||
const wrapper = document.querySelector("div.interests");
|
const wrapper = document.querySelector("div.interests");
|
||||||
wrapper.classList.remove("active");
|
wrapper.classList.remove("active");
|
||||||
|
|
||||||
[...wrapper.querySelectorAll("p")].forEach(element => {
|
|
||||||
// Reset to initial position
|
// Reset to initial position
|
||||||
element.style.setProperty("transform", "translate(0, 0)");
|
[...wrapper.querySelectorAll("p")].forEach(element => element.style.setProperty("transform", "translate(0, 0)"));
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Bind triggers for interests explosion and implotion
|
// Bind triggers for interests explosion and implotion
|
||||||
|
@ -55,10 +62,7 @@ const implodeInterests = () => {
|
||||||
// Get absolute position of the trigger element
|
// Get absolute position of the trigger element
|
||||||
const size = interestsElement.getBoundingClientRect();
|
const size = interestsElement.getBoundingClientRect();
|
||||||
|
|
||||||
const x = size.x - 80;
|
explodeInterests(size.x, size.y);
|
||||||
const y = size.y - 10;
|
|
||||||
|
|
||||||
explodeInterests(x, y);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
interestsElement.addEventListener(canHover ? "mouseleave" : "touchend", () => implodeInterests());
|
interestsElement.addEventListener(canHover ? "mouseleave" : "touchend", () => implodeInterests());
|
||||||
|
|
Loading…
Add table
Reference in a new issue