Back

Creating a Weightless Floating Feather Effect Button

Learn to create an enchanting toggle button that emulates a soft floating feather, changing state with mesmerizing airiness.

Component Explanation

Creating a Weightless Floating Feather Effect Button

This tutorial will guide you step-by-step through the creation of a delightful, airy toggle button inspired by the soft weightlessness of a feather.

HTML

We begin with the HTML structure, defining a button that will serve as our feather-inspired toggle.

The button is encapsulated within a <main> tag to leverage its semantic role for major content sections, aiding accessibility and SEO.

<main class="feather-button-container">
  <button onclick="toggleFeatherEffect()" class="feather-toggle-button" aria-label="Toggle feather effect">
    <span class="toggle-state">INACTIVE</span>
  </button>
</main>

JavaScript

The JavaScript ensures the toggle effect changes both the visual state of the button and modifies the background color, utilizing a smooth animation to mimic feather movements.
let isActive = false;
function toggleFeatherEffect() {
  const button = document.querySelector('.feather-toggle-button');
  const stateText = document.querySelector('.toggle-state');
  isActive = !isActive;
  if (isActive) {
    button.style.animation = "floating 2s infinite ease-in-out";
    stateText.textContent = "ACTIVE";
    button.classList.add('active-feather');
    document.body.style.backgroundColor = '#e0f7fa';
  } else {
    button.style.animation = "";
    stateText.textContent = "INACTIVE";
    button.classList.remove('active-feather');
    document.body.style.backgroundColor = '#ffffff';
  }
}

CSS

Our CSS uses glassmorphism, with a frosted glass effect achieved via background properties and blur filters to embrace modern design trends.
.feather-button-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
.feather-toggle-button {
  padding: 20px 40px;
  border: none;
  border-radius: 30px;
  background: rgba(255,255,255,0.6);
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #00796b;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.3s, box-shadow 0.3s;
  outline: none;
}
When active, additional CSS transforms and animations are applied to simulate the gentle floating of a feather.
.active-feather {
  transform: translateY(-10px);
  box-shadow: 0 12px 24px 0 rgba(31, 38, 135, 0.37);
}
@keyframes floating {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

Follow these steps to experience a toggle button that feels as light as air, an interaction that's as soft as a feather floating on the breeze.

Whole code

<main class="feather-button-container">
  <button onclick="toggleFeatherEffect()" class="feather-toggle-button" aria-label="Toggle feather effect">
    <span class="toggle-state">INACTIVE</span>
  </button>
</main>


<script>
let isActive = false;
function toggleFeatherEffect() {
  const button = document.querySelector('.feather-toggle-button');
  const stateText = document.querySelector('.toggle-state');
  isActive = !isActive;
  if (isActive) {
    button.style.animation = "floating 2s infinite ease-in-out";
    stateText.textContent = "ACTIVE";
    button.classList.add('active-feather');
    document.body.style.backgroundColor = '#e0f7fa';
  } else {
    button.style.animation = "";
    stateText.textContent = "INACTIVE";
    button.classList.remove('active-feather');
    document.body.style.backgroundColor = '#ffffff';
  }
}
</script>

<style>
.feather-button-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
.feather-toggle-button {
  padding: 20px 40px;
  border: none;
  border-radius: 30px;
  background: rgba(255,255,255,0.6);
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #00796b;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.3s, box-shadow 0.3s;
  outline: none;
}
.active-feather {
  transform: translateY(-10px);
  box-shadow: 0 12px 24px 0 rgba(31, 38, 135, 0.37);
}
@keyframes floating {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

</style>
      
Thank you for reading this article.

Comments

More toggle-buttons

Similar

See also