Better animated Zhen Site

This commit is contained in:
BOTAlex 2024-03-30 16:04:44 +01:00
parent e79408b9bc
commit 03cfd5a617
1 changed files with 42 additions and 4 deletions

View File

@ -1,7 +1,17 @@
<script lang="ts">
import { onMount } from 'svelte';
// Params
let mouseMoveDevider = 1.5;
// Site variables
let mouseX = 0;
let mouseY = 0;
// Element binded variables
let animatedTopBackgroundX = 0;
let animatedTopBackgroundY = 0;
let StartPageAnimated: Element;
function handleMouseMove(event: MouseEvent) {
@ -9,19 +19,39 @@
const centerX = StartPageAnimated.clientWidth / 2;
const centerY = StartPageAnimated.clientHeight / 2;
mouseX = event.clientX - StartPageAnimated.clientLeft - centerX;
mouseY = event.clientY - StartPageAnimated.clientTop - centerY;
mouseX = event.clientX;
mouseY = event.clientY;
animatedTopBackgroundX = mouseX - StartPageAnimated.clientLeft - centerX;
animatedTopBackgroundY = mouseY - StartPageAnimated.clientTop - centerY;
//console.log(mouseX+"\n"+mouseY);
}
// let windowWidth = window.innerWidth;
// let windowHeight = window.innerHeight;
// // Update window dimensions on mount
// onMount(() => {
// const updateDimensions = () => {
// windowWidth = window.innerWidth;
// windowHeight = window.innerHeight;
// };
// window.addEventListener('resize', updateDimensions);
// return () => {
// window.removeEventListener('resize', updateDimensions);
// };
// });
</script>
<div class="StartPageContainer" role="presentation" on:mousemove={handleMouseMove}>
<svelte:body on:mousemove={handleMouseMove}/>
<div class="StartPageAnimated" bind:this={StartPageAnimated} style="transform: translate({mouseX}px, {mouseY}px);">
<div class="StartPageContainer">
<div class="StartPageAnimated" bind:this={StartPageAnimated} style="transform: translate({animatedTopBackgroundX}px, {animatedTopBackgroundY}px);">
<span class="rotate45" style="display: flex; justify-content: center; align-items: center;">TEXT!!!</span>
</div>
</div>
@ -40,5 +70,13 @@
height: 100vw;
transition: all 1000ms cubic-bezier(0.16,1.63,0.01,0.99);
justify-content: center;
vertical-align: middle;
display: flex;
}
.rotate45 {
transform: rotate(-45deg); /* Rotate the element by 45 degrees */
}
</style>