HTML Copy
<button class="pp-mag" type="button" aria-pressed="false" aria-label="Play" data-pp data-pp-mag>
<span class="pp-mag-track" aria-hidden="true">
<svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true">
<path class="pp-mag-icon" d="M8 5 L8 19 L19 12 Z" fill="currentColor" />
</svg>
</span>
</button> CSS Copy
.pp-mag {
width: 60px;
height: 60px;
border: 0;
padding: 0;
background: linear-gradient(135deg, #1e3a8a, #1d4ed8);
border-radius: 18px;
color: #bfdbfe;
cursor: pointer;
position: relative;
overflow: hidden;
box-shadow:
0 8px 22px -6px rgba(29, 78, 216, 0.55),
inset 0 1px 0 rgba(255, 255, 255, 0.12);
transition:
box-shadow 0.25s,
color 0.2s;
}
.pp-mag:hover {
color: #ffffff;
}
.pp-mag:focus-visible {
outline: 3px solid rgba(29, 78, 216, 0.5);
outline-offset: 3px;
}
.pp-mag-track {
position: absolute;
inset: 0;
display: grid;
place-items: center;
transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.pp-mag-icon {
transition: d 0.3s cubic-bezier(0.5, 0, 0.3, 1.2);
}
.pp-mag[aria-pressed="true"] .pp-mag-icon {
d: path("M7 5 H10 V19 H7 Z M14 5 H17 V19 H14 Z");
}
.pp-mag[aria-pressed="true"] .pp-mag-track {
transform: translate(0, 0) !important;
}
/* ── Drop-in JS for the magnetic effect ──
document.querySelectorAll('[data-pp-mag]').forEach(btn => {
const track = btn.querySelector('.pp-mag-track');
btn.addEventListener('pointermove', e => {
const r = btn.getBoundingClientRect();
const x = ((e.clientX - r.left) / r.width - 0.5) * 12;
const y = ((e.clientY - r.top) / r.height - 0.5) * 12;
track.style.transform = `translate(${x}px, ${y}px)`;
});
btn.addEventListener('pointerleave', () => {
track.style.transform = 'translate(0, 0)';
});
});
*/ JS Copy
// ── Drop this on every page where you render a play/pause button ──
// Toggles aria-pressed + aria-label on click. The CSS handles all visuals.
document.querySelectorAll('[data-pp]').forEach(function (btn) {
btn.addEventListener('click', function () {
var playing = btn.getAttribute('aria-pressed') === 'true';
btn.setAttribute('aria-pressed', String(!playing));
btn.setAttribute('aria-label', !playing ? 'Pause' : 'Play');
});
});