Skip to content

Commit

Permalink
minor fixes on layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Ciminieri committed Sep 19, 2024
1 parent 3bb33b1 commit a2c1cc7
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 57 deletions.
110 changes: 63 additions & 47 deletions src/lib/components/DataProject.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import ImageGallery from './ImageGallery.svelte';
import { urlFor } from '$lib/sanityClient';
import { browser } from '$app/environment';
import { slide } from 'svelte/transition';
import { cubicInOut } from 'svelte/easing';
const { project, corsoColor } = $props();
let showModal = $state(false);
let currentMediaIndex = $state(0);
Expand All @@ -22,7 +25,6 @@
}
function handleImageClick(index) {
//console.log('handleImageClick');
showModal = true;
isVideo = false;
currentMediaIndex = index;
Expand All @@ -33,15 +35,13 @@
}
function nextMedia() {
//console.log('nextMedia');
if (isVideo) return;
if (currentMediaIndex < project.immagini.length - 1) {
currentMediaIndex++;
}
}
function prevMedia() {
//console.log('prevMedia');
if (isVideo) return;
if (currentMediaIndex > 0) {
currentMediaIndex--;
Expand All @@ -61,10 +61,8 @@
});
$effect(() => {
//console.log(browser, showModal, !isVideo, modalContent, Hammer, 'check');
if (browser && showModal && !isVideo && modalContent && Hammer) {
const hammer = new Hammer(modalContent);
//console.log('Hammer initialized');
hammer.on('swipeleft', nextMedia);
hammer.on('swiperight', prevMedia);
Expand Down Expand Up @@ -106,36 +104,14 @@
{#if showModal}
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div class="modal" style="display: block;" onclick={handleOutsideClick}>
<div class="modal modal-xl" style="display: block" onclick={handleOutsideClick}>
<div
class="modal-backdrop fade show"
style="opacity: 0.5; background-color: #{corsoColor};"
></div>
<div class="modal-dialog modal-lg" style="z-index: 1050;">
<div class="modal-content bg-transparent border-0">
<div
class="modal-header bg-transparent d-flex justify-content-between align-items-center border-0"
>
<div class="d-flex">
{#if !isVideo && project.immagini && project.immagini.length > 1}
<button
class="btn d-flex me-2 align-items-center justify-content-center hover-effect bg-black text-white"
style="--corso-color: #{corsoColor}; width: 40px; height: 40px; border-radius: 50%;"
onclick={prevMedia}
class:opacity-0={currentMediaIndex === 0}
>
<i class="bi bi-arrow-left"></i>
</button>
<button
class="btn d-flex align-items-center justify-content-center hover-effect bg-black text-white"
style="--corso-color: #{corsoColor}; width: 40px; height: 40px; border-radius: 50%;"
onclick={nextMedia}
class:opacity-0={currentMediaIndex === project.immagini.length - 1}
>
<i class="bi bi-arrow-right"></i>
</button>
{/if}
</div>
<div class="modal-dialog modal-dialog-centered" style="z-index: 1050;">
<div class="modal-content">
<div class="modal-header d-flex justify-content-center align-items-center border-0">
<button
type="button"
class="btn px-3 py-2 rounded-pill border-0 hover-effect bg-black text-white"
Expand All @@ -145,30 +121,61 @@
Chiudi
</button>
</div>
<div class="modal-body position-relative bg-black" bind:this={modalContent}>
<div
class="modal-body d-flex align-items-center justify-content-center p-0 position-relative"
bind:this={modalContent}
>
<!-- svelte-ignore legacy_code -->
{#if isVideo && project.video}
<!-- svelte-ignore a11y_media_has_caption -->
<video autoplay controls width="100%">
<video
autoplay
controls
style="max-width: 100%; max-height: calc(100vh - 200px); object-fit: contain;"
>
<source src={getVideoUrl(project.video)} type="video/mp4" />
Your browser does not support the video tag.
</video>
{:else if project.immagini && project.immagini.length > 0}
<div class="swipable-container" style="overflow: hidden;">
<div
class="swipable-content"
style="display: flex; transition: transform 0.3s ease; transform: translateX(-{currentMediaIndex *
100}%);"
>
{#each project.immagini as image, index}
<img
src={urlFor(image).url()}
alt={`Project image ${index + 1}`}
style="width: 100%; height: auto; flex-shrink: 0;"
/>
{/each}
</div>
<div
class="image-container"
style="width: 100%; height: calc(100vh - 200px); position: relative; overflow: hidden;"
>
{#each project.immagini as image, index}
{#if Math.abs(index - currentMediaIndex) <= 1}
<div
in:slide={{ duration: 300, easing: cubicInOut }}
out:slide={{ duration: 300, easing: cubicInOut }}
style="position: absolute; top: 0; left: {(index - currentMediaIndex) *
100}%; width: 100%; height: 100%; transition: left 0.3s ease;"
>
<img
src={urlFor(image).url()}
alt={`Project image ${index + 1}`}
style="width: 100%; height: 100%; object-fit: contain; object-position: top;"
/>
</div>
{/if}
{/each}
</div>
{#if !isVideo && project.immagini && project.immagini.length > 1}
<button
class="btn d-none d-md-flex align-items-center justify-content-center hover-effect bg-black text-white position-absolute"
style="--corso-color: #{corsoColor}; width: 60px; height: 60px; border-radius: 50%; left: 10px; top: 50%; transform: translateY(-50%);"
onclick={prevMedia}
class:opacity-0={currentMediaIndex === 0}
>
<i class="bi bi-arrow-left"></i>
</button>
<button
class="btn d-none d-md-flex align-items-center justify-content-center hover-effect bg-black text-white position-absolute"
style="--corso-color: #{corsoColor}; width: 60px; height: 60px; border-radius: 50%; right: 10px; top: 50%; transform: translateY(-50%);"
onclick={nextMedia}
class:opacity-0={currentMediaIndex === project.immagini.length - 1}
>
<i class="bi bi-arrow-right"></i>
</button>
{/if}
{/if}
</div>
</div>
Expand All @@ -187,4 +194,13 @@
background-color: white !important;
color: var(--corso-color) !important;
}
.modal-content {
background-color: transparent;
border: none;
}
.image-container {
display: flex;
align-items: center;
justify-content: center;
}
</style>
59 changes: 59 additions & 0 deletions src/lib/cursorEffect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Configuration variables for the grid
const MIN_GRID_SIZE = 50; // Minimum size of each grid cell in pixels
const MAX_GRID_SIZE = 50; // Maximum size of each grid cell in pixels
const ANIMATION_DURATION = 1000; // Duration of the square's visibility in milliseconds
const PADDING = 0; // Padding between squares in pixels
const BORDER_ONLY = false; // If true, only draw the border of the div

/**
* Creates a square div at the mouse position and fades it out
* @param {number} x - The x-coordinate of the mouse
* @param {number} y - The y-coordinate of the mouse
*/
export function createSquareAtMouse(x, y) {
// Generate a random grid size within the configured range
const GRID_SIZE = Math.floor(Math.random() * (MAX_GRID_SIZE - MIN_GRID_SIZE + 1)) + MIN_GRID_SIZE;

// Calculate the grid cell position
const cellX = Math.floor(x / (GRID_SIZE + PADDING)) * (GRID_SIZE + PADDING);
const cellY = Math.floor(y / (GRID_SIZE + PADDING)) * (GRID_SIZE + PADDING);

// Check if a square already exists at this position
const existingSquare = document.querySelector(`div[data-x="${cellX}"][data-y="${cellY}"]`);
if (existingSquare) {
return; // If a square already exists, don't create a new one
}

// Create the square div
const square = document.createElement('div');
square.style.position = 'absolute';
square.style.left = `${cellX}px`;
square.style.top = `${cellY}px`;
square.style.width = `${GRID_SIZE}px`;
square.style.height = `${GRID_SIZE}px`;
square.style.mixBlendMode = 'difference'; // This will invert the colors underneath
square.style.pointerEvents = 'none'; // Ensure it doesn't interfere with other elements
square.style.transition = 'opacity ' + ANIMATION_DURATION / 1000 + 's ease-out'; // Add transition for fading effect
square.dataset.x = cellX; // Add data attributes to identify the square's position
square.dataset.y = cellY;

if (BORDER_ONLY) {
square.style.border = '3px solid rgba(0, 0, 255, 0.8)'; // Blue border with 80% opacity
square.style.backgroundColor = 'transparent'; // Transparent background
} else {
square.style.backgroundColor = 'rgba(0, 0, 255, 0.8)'; // Use blue with 80% opacity
}

// Add the square to the document
document.body.appendChild(square);

// Start the fading effect after a short delay
setTimeout(() => {
square.style.opacity = '0';
}, 50);

// Remove the square after the animation completes
setTimeout(() => {
document.body.removeChild(square);
}, ANIMATION_DURATION);
}
2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Header from '$lib/components/Header.svelte';
</script>

<div class="container-xl">
<div class="container-xxl">
<Header />
<slot />
</div>
35 changes: 29 additions & 6 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
<script>
import { base } from '$app/paths';
import { createSquareAtMouse } from '$lib/cursorEffect.js';
const page = $props();
const corsi = $derived(page.data.corsi);
let firstContainer;
$effect(() => {
if (!firstContainer) return;
const handleMouseMove = (event) => {
const rect = firstContainer.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
if (x >= 0 && x <= rect.width && y >= 0 && y <= rect.height) {
createSquareAtMouse(event.clientX, event.clientY);
}
};
firstContainer.addEventListener('mousemove', handleMouseMove);
return () => {
firstContainer.removeEventListener('mousemove', handleMouseMove);
};
});
</script>

<div class="container-fluid mt-2">
<div class="container-fluid mt-2" bind:this={firstContainer}>
<div class="row justify-content-between">
<div class="col-md-7 col-sm-12">
<p class="fw-semibold fs-3">
Il laboratorio di Information Design, sviluppato su due moduli integrati, ha lobiettivo di
Il laboratorio di Information Design, sviluppato su due moduli integrati, ha l'obiettivo di
introdurre gli studenti alla progettazione di artefatti comunicativi che hanno lo scopo di
veicolare temi e informazioni complesse e offrire una visione ampia sul valore, sulle
potenzialità e i limiti dei dati. Gli studenti, organizzati in gruppi di lavoro, partiranno
dalla selezione di un tema di ricerca che svilupperanno tramite la selezione e lanalisi
dalla selezione di un tema di ricerca che svilupperanno tramite la selezione e l'analisi
visuale di set di dati che ne rappresentano alcune dimensioni. Dopo una prima fase di
analisi, gli studenti dovranno sviluppare un progetto composto da tre elementi: una
pubblicazione digitale in grado di presentare il tema e i dati analizzati;
uninstallazione/campagna di comunicazione capace di riportare lesperienza digitale in uno
spazio fisico; un video che racconta lintera esperienza in tutte le sue fasi significative.
un'installazione/campagna di comunicazione capace di riportare l'esperienza digitale in uno
spazio fisico; un video che racconta l'intera esperienza in tutte le sue fasi significative.
</p>
</div>
<div class="col-md-4 col-sm-12 mt-2">
Expand Down Expand Up @@ -54,7 +77,7 @@
<div class="col-12">
<h1 class="d-flex align-items-center gap-3">
<a href="{base}/corsi/{corso.slug.current}" class="text-decoration-none text-white">
<span class="fw-normal">{corso.titolo}</span>
<span class="fw-normal text-uppercase">{corso.titolo}</span>
</a>
<span
class="badge rounded-pill text-white border border-white fs-6 mt-2"
Expand Down
4 changes: 2 additions & 2 deletions src/routes/corsi/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="row">
<div class="col-md-12 border-bottom border-white py-2">
<h1 class="d-flex align-items-center gap-3">
<span class="fw-normal">{data.corso.titolo}</span>
<span class="fw-normal text-uppercase">{data.corso.titolo}</span>
<span
class="badge rounded-pill text-white border border-white fs-6 mt-2"
style="background-color: {'#' + data.corso.colore}">{data.corso.anno}</span
Expand All @@ -35,7 +35,7 @@
class:border-bottom={index !== data.corso.gruppi.length - 1}
>
<a href="{base}/gruppi/{gruppo.slug.current}" class="text-decoration-none text-white">
<h1 class="fw-normal text-uppercase">{gruppo.nome}</h1>
<h1 class="fw-normal text-uppercase" style="font-size: 4rem;">{gruppo.nome}</h1>
</a>
</div>
{/each}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/gruppi/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
href="{base}/corsi/{data.gruppo.corso.slug.current}"
class="text-decoration-none text-white"
>
<span class="fw-normal">{data.gruppo.corso.titolo}</span>
<span class="fw-normal text-uppercase">{data.gruppo.corso.titolo}</span>
</a>
<span
class="badge rounded-pill text-white border border-white fs-6 mt-2"
Expand Down

0 comments on commit a2c1cc7

Please sign in to comment.