Frontend: Added updateTimeLine() which reset the position of the slidestring array each time a resizing occurs. Updated CSS so that the sidebar is not shown if in mobile mode.

This commit is contained in:
Yohan Boujon 2024-01-15 23:48:03 +01:00
parent 282627ed0d
commit d3aceced88
4 changed files with 222 additions and 152 deletions

View file

@ -5,6 +5,7 @@
import { onMount } from "svelte"; import { onMount } from "svelte";
import { import {
createTimeLine, createTimeLine,
updateTimeLine,
slideContainerCount, slideContainerCount,
slideTimelineCount, slideTimelineCount,
slideStringCount, slideStringCount,
@ -15,17 +16,20 @@
export let type; export let type;
export let timeline = false; export let timeline = false;
export let reverse = false; export let reverse = false;
if(reverse) { if (reverse) {
data = data.reverse(); data = data.reverse();
} }
// Slideshow global variables // Resizing variables
let resizing = false;
// Slideshow global variables
let slideshow_index = 0; let slideshow_index = 0;
let slideshow_hidden = []; let slideshow_hidden = [];
let slideshowTimeline; let slideshowTimeline;
let slideshowElements; let slideshowElements;
let slideshowBubbles;
// Timeline global variables // Timeline global variables
let slideshow; let slideshow;
@ -36,7 +40,7 @@
const currentSlideCount = $slideContainerCount; const currentSlideCount = $slideContainerCount;
// Sliced array from currentSlideCount to data.length // Sliced array from currentSlideCount to data.length
slideshowElements = Array.from( slideshowElements = Array.from(
document.querySelectorAll(".slide-container") document.querySelectorAll(".slide-container"),
).slice(currentSlideCount, currentSlideCount + data.length); ).slice(currentSlideCount, currentSlideCount + data.length);
// Updating with the current length // Updating with the current length
slideContainerCount.update((value) => { slideContainerCount.update((value) => {
@ -48,8 +52,8 @@
//global writer count //global writer count
const currentTimelineCount = $slideTimelineCount; const currentTimelineCount = $slideTimelineCount;
// Creating the string between the bubbles // Creating the string between the bubbles
const slideshowBubbles = Array.from( slideshowBubbles = Array.from(
document.querySelectorAll(".slide-bubble") document.querySelectorAll(".slide-bubble"),
).slice(currentTimelineCount, currentTimelineCount + data.length); ).slice(currentTimelineCount, currentTimelineCount + data.length);
// Creating strings // Creating strings
@ -59,40 +63,15 @@
top: element.offsetTop, top: element.offsetTop,
}); });
} }
const stringTimelineElements = createTimeLine(bubbles);
for (const div of stringTimelineElements) { createTimelineStrings();
slideshow.appendChild(div);
}
// Updating with the current length
slideTimelineCount.update((value) => {
return value + data.length;
});
//global writer count
const currentStringCount = $slideStringCount;
// Sliced array from currentTimelineCount to data.length
slideshowTimeline = Array.from(
document.querySelectorAll(".slide-string")
).slice(
currentStringCount,
currentStringCount + stringTimelineElements.length
);
// Updating with the current length
slideStringCount.update((value) => {
return value + stringTimelineElements.length;
});
} }
}); });
function slideCards() { function slideCards() {
// Set or reset slideshow index, hidden array and timeling. // Set or reset slideshow index, hidden array and timeling.
if (slideshow_index >= data.length - 1) { if (slideshow_index >= data.length - 1) {
slideshow_hidden = []; resetSlideCards();
slideshow_index = 0;
if (timeline) {
for (const timeline of slideshowTimeline) {
timeline.style.backgroundColor = "";
}
}
} else { } else {
slideshow_hidden.push(slideshow_index); slideshow_hidden.push(slideshow_index);
slideshow_index++; slideshow_index++;
@ -105,7 +84,6 @@
} }
// Translating elements // Translating elements
console.log(slideshowTimeline)
slideshowElements.forEach((element, id) => { slideshowElements.forEach((element, id) => {
/* Slideshow translating*/ /* Slideshow translating*/
let newtransformValue = transformValue; let newtransformValue = transformValue;
@ -115,12 +93,11 @@
} }
element.style.transform = `translateX(-${newtransformValue}px)`; element.style.transform = `translateX(-${newtransformValue}px)`;
/* Slideshow Timeline trnaslating */ /* Slideshow Timeline translating */
if (timeline) { if (timeline) {
if (slideshowTimeline[id] != undefined) { if (slideshowTimeline[id] != undefined) {
slideshowTimeline[ slideshowTimeline[id].style.transform =
id `translateX(-${transformValue}px)`;
].style.transform = `translateX(-${transformValue}px)`;
if (slideshow_hidden.includes(id)) { if (slideshow_hidden.includes(id)) {
slideshowTimeline[id].style.backgroundColor = slideshowTimeline[id].style.backgroundColor =
"var(--color-background)"; "var(--color-background)";
@ -129,8 +106,68 @@
} }
}); });
} }
function resetSlideCards() {
return new Promise((resolve) => {
slideshow_hidden = [];
slideshow_index = 0;
for (const element of slideshowElements) {
element.style.transform = "";
}
if (timeline) {
for (const timeline of slideshowTimeline) {
timeline.style.backgroundColor = "";
timeline.style.transform = "";
}
}
resolve();
});
}
function createTimelineStrings() {
const stringTimelineElements = createTimeLine(bubbles);
for (const div of stringTimelineElements) {
slideshow.appendChild(div);
}
// Updating with the current length
slideTimelineCount.update((value) => {
return value + data.length;
});
//global writer count
const currentStringCount = $slideStringCount;
/* Sliced array from currentTimelineCount to data.length
Everytime a slideshow created the slide string, the queryselector all will get all the elements
We do not want that and only want the slide-string we are interested in
Starting from the oldest count, finishing by our actual length */
slideshowTimeline = Array.from(
document.querySelectorAll(".slide-string"),
).slice(
currentStringCount,
currentStringCount + stringTimelineElements.length,
);
// Updating with the current length
slideStringCount.update((value) => {
return value + stringTimelineElements.length;
});
}
async function changeSize() {
if (timeline && !resizing) {
resizing = true;
await resetSlideCards();
await new Promise(resolve => setTimeout(resolve, 400));
updateTimeLine(slideshowTimeline, slideshowBubbles);
resizing = false;
//global writer count
}
}
</script> </script>
<svelte:window on:resize={changeSize} />
<div class="slideshow" bind:this={slideshow}> <div class="slideshow" bind:this={slideshow}>
<button class="slideshow_btn" on:click={slideCards}> <button class="slideshow_btn" on:click={slideCards}>
<div> <div>

View file

@ -11,21 +11,38 @@ html {
flex-direction: row; flex-direction: row;
} }
.sidebar {
@media screen and (min-width: 1200px)
{
.sidebar {
position: absolute; position: absolute;
width: 16rem; width: 16rem;
height: 75rem; height: 75rem;
background-color: var(--color-special); background-color: var(--color-special);
z-index: 2; z-index: 2;
transition: all 0s ease 0s; transition: all 0s ease 0s;
} }
.fake-sidebar { .fake-sidebar {
width: 100%; width: 100%;
flex-basis: 20rem; flex-basis: 20rem;
box-shadow: rgba(50, 50, 93, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px; box-shadow: rgba(50, 50, 93, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px;
background-color: var(--color-special); background-color: var(--color-special);
z-index: 1; z-index: 1;
}
}
@media screen and (max-width: 1200px)
{
.sidebar {
position: absolute;
width: 16rem;
height: 75rem;
background-color: var(--color-special);
z-index: 2;
transition: all 0s ease 0s;
visibility: hidden;
}
} }
.profile-picture-container { .profile-picture-container {

View file

@ -16,6 +16,16 @@ export function createTimeLine(positionsArray) {
return divArray; return divArray;
} }
export function updateTimeLine(slideStringArray, positionsArray) {
for (let i = 0; i < positionsArray.length - 1; i++)
{
const left = positionsArray[i].offsetLeft + (2.5 * 16);
const top = positionsArray[i].offsetTop + 16;
slideStringArray[i].style.left = `${left}px`;
slideStringArray[i].style.top = `${top}px`;
}
}
export let slideContainerCount = writable(0); export let slideContainerCount = writable(0);
export let slideTimelineCount = writable(0); export let slideTimelineCount = writable(0);
export let slideStringCount = writable(0); export let slideStringCount = writable(0);

View file

@ -64,9 +64,15 @@
sidebar.style.top = ''; sidebar.style.top = '';
} }
} }
// Mobile check
$: innerWidth = 0;
function mobileCheck() {
//console.log(innerWidth);
}
</script> </script>
<svelte:window bind:scrollY bind:innerHeight on:scroll={sidebarScrollingHandler} /> <svelte:window bind:scrollY bind:innerHeight bind:innerWidth on:scroll={sidebarScrollingHandler} on:resize={mobileCheck} />
{#if data.status == 0} {#if data.status == 0}
<div class="container-cv"> <div class="container-cv">