Hello All,
I have a portfolio page displaying a list of projects randomly, with each item assigned to a unique CSS position. (Thanks again for the help on this one @texnixe.)
Now I would like this portfolio page background color to change depending on which project / thumbnail is being hovered.
I have my colors set for each project using kirby-color plugin so each page has its own color assigned (and can be changed into the panel), labeled as color.
I believe there is a few different ways to tackle this, but how would you guys go about this ?
my random portfolio index goes as follow:
<main class="main">
<h1><?= $page->title() ?></h1>
<?php $projects = $page->children()->listed()->shuffle()->limit(15); ?>
<ul>
<?php foreach ($projects as $project): ?>
<li class="overview-item <?= 'position-' . ($projects->indexOf($project) + 1) ?>">
<div class="<?= $project->color() ?>">
<a href="<?= $project->url() ?>">
<figure>
<img src="<?= $project->image()->url() ?>" class="lazy" alt="<?= $project->alt() ?>">
<figcaption><?= $project->title() ?></figcaption>
</figure>
</a>
</div>
</li>
<?php endforeach ?>
</ul>
</main>
Now something that seems much fancier than inline js, would be creating unique IDs and divs (only need hover, then revert to overview/portofolio color):
<?php if(isset($project)) : ?>
...
<?php $colors = [];
<?php foreach($projects as $project): ?>
<?php $class = 'background-' . uniqid(); $colors[$class] = $project; ?>
<div class="<?= $class ?>">
...
</div>
<?php endforeach ?>
<style>
<?php foreach($colors as $class => $project): ?>
.<?= $class ?> {
background: <?= $project->primary_color() ?>;
}
.<?= $class ?>:hover, .<?= $class ?>:focus {
background: <?= $project->secondary_color() ?>;
}
<?php endforeach ?>
</style>
Now I don’t know if that’s the best route, since I might want to transition with fade and/or ease colors and I have also no clue how to plug the latter into the former…
Let me know your thoughts and in case you didn’t notice total beginner here
Many thanks,
v