implement animations on scroll

This commit is contained in:
Michi 2025-03-20 21:49:02 +01:00
parent f5745b9e81
commit 448ae8a49b
5 changed files with 121 additions and 33 deletions

View file

@ -1,11 +1,11 @@
<div id="about" class="about"> <div id="about" class="about">
{{ with .Site.GetPage "about" }} {{ with .Site.GetPage "about" }}
<div class="about-part"> <div class="about-part fade-left">
{{ with .Params.image }} {{ with .Params.image }}
<img src='{{ . | relURL }}' alt="{{ $.Params.title }}" title="{{ $.Params.title }}"> <img src='{{ . | relURL }}' alt="{{ $.Params.title }}" title="{{ $.Params.title }}">
{{ end }} {{ end }}
</div> </div>
<div class="about-part"> <div class="about-part fade-right">
<h1>{{ .Title }}</h1> <h1>{{ .Title }}</h1>
<div>{{ .Content }}</div> <div>{{ .Content }}</div>
</div> </div>

View file

@ -1,8 +1,8 @@
<div id="contact" class="contact"> <div id="contact" class="contact">
<div class="contact-title-wrapper"> <div class="contact-title-wrapper fade-up">
<h1 class="contact-title">{{ T "contact-me" }}</h1> <h1 class="contact-title">{{ T "contact-me" }}</h1>
</div> </div>
<div> <div class="fade-up">
{{ range .Site.Data.socialmedia }} {{ range .Site.Data.socialmedia }}
<a href="{{ .link }}" alt="{{ .name }}" title="{{ .name }}"><i class="{{ .icon }}"></i></a> <a href="{{ .link }}" alt="{{ .name }}" title="{{ .name }}"><i class="{{ .icon }}"></i></a>
{{ end }} {{ end }}

View file

@ -1,6 +1,6 @@
<div id="projects" class="projects"> <div id="projects" class="projects">
<h1>{{ T "projects" }}</h1> <h1 class="fade-up">{{ T "projects" }}</h1>
<div class="tag-filter"> <div class="tag-filter fade-up">
{{ range .Site.Data.tags }} {{ range .Site.Data.tags }}
<div class="tag"> <div class="tag">
<input class="tag-checkbox" id="tag-{{ .slug }}" value="{{ .slug }}" type="checkbox" {{ if .checked }} checked {{ end }}> <input class="tag-checkbox" id="tag-{{ .slug }}" value="{{ .slug }}" type="checkbox" {{ if .checked }} checked {{ end }}>
@ -11,7 +11,7 @@
<div class="project-list"> <div class="project-list">
</div> </div>
<div> <div class="fade-up">
<button class="project-load-btn" alt='{{ T "load-more" }}' title='{{ T "load-more" }}' name='{{ T "load-more" }}'>{{ T "load-more" }}</button> <button class="project-load-btn" alt='{{ T "load-more" }}' title='{{ T "load-more" }}' name='{{ T "load-more" }}'>{{ T "load-more" }}</button>
</div> </div>
</div> </div>

View file

@ -70,20 +70,27 @@ function updateNavStyle(){
// intersection observer for animations // intersection observer for animations
// credits: https://coolcssanimation.com/how-to-trigger-a-css-animation-on-scroll/ // credits: https://coolcssanimation.com/how-to-trigger-a-css-animation-on-scroll/
const observer = new IntersectionObserver(entries => { function animationOnScroll(triggerSelector, animationClass, targetElement){
entries.forEach(entry => { const trigger = document.querySelector(triggerSelector);
const actionObject = entry.target.querySelector('.contact-title'); const target = ((targetElement) ? document.querySelector(targetElement) : trigger);
if (entry.isIntersecting) { if(trigger){
actionObject.classList.add('typewriter-animation'); const observer = new IntersectionObserver(entries => {
return; entries.forEach(entry => {
} if (entry.isIntersecting) {
target.classList.add(animationClass);
actionObject.classList.remove('typewriter-animation'); }
}); else{
}); target.classList.remove(animationClass);
}
observer.observe(document.querySelector('.contact-title-wrapper')); });
}, { rootMargin: '0px 0px 5% 0px', threshold: 0.1 });
return observer.observe(trigger);
}
}
animationOnScroll('.contact-title-wrapper', 'typewriter-animation', '.contact-title');
// calculate age // calculate age
function calculateAge(selector){ function calculateAge(selector){
@ -145,8 +152,9 @@ async function getProjectCard(data){
}); });
const container = document.createElement("div"); const container = document.createElement("div");
container.classList = "project-card"; container.classList = "project-card fade-up";
container.classList.add(category); container.classList.add(category);
//container.style.animation = "fade-up var(--baseDuration) linear";
//container.style.backgroundImage = `url(${image})`; //container.style.backgroundImage = `url(${image})`;
const cardFirst = document.createElement("div"); const cardFirst = document.createElement("div");

View file

@ -22,6 +22,9 @@ body{
--baseTransition: all var(--baseDuration); --baseTransition: all var(--baseDuration);
--baseDuration: 250ms; --baseDuration: 250ms;
--navSmallHeight: 66px; --navSmallHeight: 66px;
--animationOffset: 100px;
--animationScale: 0.75;
--animationCoverValue: 40%;
} }
/* CONTENT */ /* CONTENT */
@ -434,17 +437,6 @@ nav.small .nav-links a:last-child:focus{
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.705); box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.705);
overflow: hidden; overflow: hidden;
position: relative; position: relative;
animation: fadeIn 400ms linear;
}
@keyframes fadeIn{
0%{
opacity: 0;
}
100%{
opacity: 1;
}
} }
.card-first img{ .card-first img{
@ -755,4 +747,92 @@ nav.small .nav-links a:last-child:focus{
transition: var(--baseTransition); transition: var(--baseTransition);
border: 1px solid var(--primary); border: 1px solid var(--primary);
outline: none; outline: none;
}
/* GENERAL ANIMATIONS */
/* only css on scroll animations: https://www.youtube.com/watch?v=0TnO1GzKWPc */
@media (prefers-reduced-motion: no-preference){
.fade-up{
animation: fade-up linear;
animation-timeline: view();
animation-composition: add;
animation-range: entry 0 cover var(--animationCoverValue);
}
.fade-down{
animation: fade-down var(--baseDuration) linear;
animation-timeline: view();
animation-composition: add;
animation-range: entry 0 cover var(--animationCoverValue);
}
.fade-left{
animation: fade-left var(--baseDuration) linear;
animation-timeline: view();
animation-composition: add;
animation-range: entry 0 cover var(--animationCoverValue);
}
.fade-right{
animation: fade-right var(--baseDuration) linear;
animation-timeline: view();
animation-composition: add;
animation-range: entry 0 cover var(--animationCoverValue);
}
}
@keyframes fade-up{
0%{
opacity: 0;
translate: 0px var(--animationOffset);
scale: var(--animationScale);
}
100%{
opacity: 1;
translate: 0px 0px;
scale: 1;
}
}
@keyframes fade-down{
0%{
opacity: 0;
translate: 0px calc(var(--animationOffset) * -1);
scale: var(--animationScale);
}
100%{
opacity: 1;
translate: 0px 0px;
scale: 1;
}
}
@keyframes fade-left{
0%{
opacity: 0;
translate: calc(var(--animationOffset) * -1) 0px;
scale: var(--animationScale);
}
100%{
opacity: 1;
translate: 0px 0px;
scale: 1;
}
}
@keyframes fade-right{
0%{
opacity: 0;
translate: var(--animationOffset) 0px;
scale: var(--animationScale);
}
100%{
opacity: 1;
translate: 0px 0px;
scale: 1;
}
} }