Back

Unveiling the Scented Book Pagination

Reimagine page turning with pagination that evokes the subtlety and nostalgia of flipping through an old book, complete with motion and hints of synesthetic aroma.

Component Explanation

Scented Book Pagination UI: A Sensory Navigation Revolution

Embark on a journey to create a pagination component that melds the tactile memory of flipping through old books with the freshness of digital interactivity. This component will offer a uniquely immersive navigation experience.

HTML: Structuring the Navigation

Begin with semantic HTML. A <nav> element signifies our navigation component, vital for accessibility. Inside, we have buttons for page navigation and a text span indicating the current page.

<div class="scented-book-container">
  <nav aria-label="Book navigation">
    <button aria-label="Previous Page" onclick="flipPage('prev')" class="page-button"></button>
    <span class="page-indicator">Page 1 of 10</span>
    <button aria-label="Next Page" onclick="flipPage('next')" class="page-button">></button>
  </nav>
</div>

Each interactive element includes an aria-label for screen readers, promoting navigational clarity. The container style ensures the layout's neat appearance.

JavaScript: Dynamic Page Logic

JavaScript connects the dots, allowing button clicks to signal page changes. The flipPage function increments or decrements the page number, updating our visual page indicator and background color, reflecting the mood of each page.

let currentPage = 1;
const totalPages = 10;

function flipPage(direction) {
  const pageIndicator = document.querySelector('.page-indicator');
  if (direction === 'next' && currentPage < totalPages) {
    currentPage++;
  } else if (direction === 'prev' && currentPage > 1) {
    currentPage--;
  }
  pageIndicator.textContent = `Page ${currentPage} of ${totalPages}`;
  document.body.style.backgroundColor = `hsl(${(currentPage/totalPages) * 360}, 70%, 80%)`;
  if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
    document.body.style.transition = 'none';
  } else {
    document.body.style.transition = 'background-color 1s';
  }
}

Accessibility is enhanced with prefers-reduced-motion checks to accommodate users who opt out of animations. Thus, interactivity remains non-intrusive.

CSS: A Visual and Tectile Artwork

Here, styles converge to conjure our scented book metaphor. A backdrop-filter subtly echoes glassmorphism, while box-shadow gives depth, reminiscent of the layers and textures in book pages.

.scented-book-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
.scented-book-container nav {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  padding: 10px 20px;
  border-radius: 15px;
  box-shadow: 10px 10px 30px rgba(0, 0, 0, 0.1);
}
.page-button {
  border: none;
  background: none;
  font-size: 24px;
  margin: 0 15px;
  cursor: pointer;
  transition: transform 0.5s;
}
.page-button:focus {
  outline: 3px solid #007BFF;
}
.page-button:hover {
  transform: scale(1.2);
  color: #007BFF;
}
.page-indicator {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

Attention to hover and focus states ensures interactions feel humane and satisfying, with visual cues ensuring users always know where they are.

Thus, we invite viewers to not just browse, but to feel each page's turning like a fresh whisper of a long-lost fragrance, embodied in an interactive UI.

Whole code

<div class="scented-book-container">
  <nav aria-label="Book navigation">
    <button aria-label="Previous Page" onclick="flipPage('prev')" class="page-button">&lt;</button>
    <span class="page-indicator" role="text">Page 1 of 10</span>
    <button aria-label="Next Page" onclick="flipPage('next')" class="page-button">&gt;</button>
  </nav>
</div>


<script>
let currentPage = 1;
const totalPages = 10;

function flipPage(direction) {
  const pageIndicator = document.querySelector('.page-indicator');
  if (direction === 'next' && currentPage < totalPages) {
    currentPage++;
  } else if (direction === 'prev' && currentPage > 1) {
    currentPage--;
  }
  pageIndicator.textContent = `Page ${currentPage} of ${totalPages}`;
  document.body.style.backgroundColor = `hsl(${(currentPage/totalPages) * 360}, 70%, 80%)`;
  if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
    document.body.style.transition = 'none';
  } else {
    document.body.style.transition = 'background-color 1s';
  }
}
</script>

<style>
.scented-book-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
.scented-book-container nav {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  padding: 10px 20px;
  border-radius: 15px;
  box-shadow: 10px 10px 30px rgba(0, 0, 0, 0.1);
}
.page-button {
  border: none;
  background: none;
  font-size: 24px;
  margin: 0 15px;
  cursor: pointer;
  transition: transform 0.5s;
}
.page-button:focus {
  outline: 3px solid #007BFF;
}
.page-button:hover {
  transform: scale(1.2);
  color: #007BFF;
}
.page-indicator {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

</style>
      
Thank you for reading this article.

Comments

No comments yet. Be the first to comment!

More paginations

Similar

See also