DevPlatform
Home
Components
Search
Submit
Earn
Login
Sign Up Free
Magenetic - Preview | DevPlatform
DevPlatform
Categories
Accordion
Animation
Box Shadow
Button
Card
Footer
Form
Gallery
Hero Section
Inputs
Loader
Marquee
Modal
Modules
Navbar
Progress Bar
Radio Buttons
Search-Bar
Sections
Slider
Tab
Timeline
Toggle
Magenetic
jitesh208
Jan 20, 2026
2
0
Share
Live Preview
Refresh
Live Editor
HTML
CSS
JS
HTML
CSS
JavaScript
1
<button class="magnetic-button"> <span class="magnetic-text">MAGNETIC</span> </button>
1
* { margin: 0; padding: 0; box-sizing: border-box; } body { min-height: 100vh; display: flex; justify-content: center; align-items: center; background: radial-gradient(circle, #1a1a2e, #0f0f1e); font-family: 'Arial', sans-serif; overflow: hidden; } .magnetic-button { position: relative; padding: 35px 100px; font-size: 30px; font-weight: bold; background: linear-gradient(135deg, #f72585, #7209b7); border: none; border-radius: 60px; cursor: pointer; transition: all 0.1s ease; box-shadow: 0 20px 60px rgba(247, 37, 133, 0.5); transform-origin: center; } .magnetic-text { color: white; text-transform: uppercase; letter-spacing: 3px; position: relative; z-index: 2; } .magnetic-button::before { content: ''; position: absolute; top: -5px; left: -5px; right: -5px; bottom: -5px; background: linear-gradient(135deg, #f72585, #7209b7, #4cc9f0); border-radius: 65px; z-index: -1; opacity: 0; filter: blur(20px); transition: opacity 0.3s ease; } .magnetic-button:hover::before { opacity: 1; animation: glow-pulse 1.5s infinite; } @keyframes glow-pulse { 0%, 100% { filter: blur(20px); } 50% { filter: blur(30px); } } .magnetic-button:active { transform: scale(0.95); } .field-line { position: absolute; width: 200px; height: 2px; background: linear-gradient(90deg, transparent, rgba(76, 201, 240, 0.8), transparent); pointer-events: none; opacity: 0; } .magnetic-button.active .field-line { animation: field-pulse 1s ease-out; } @keyframes field-pulse { 0% { opacity: 0; transform: scale(0); } 50% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.5); } }
1
const btn = document.querySelector('.magnetic-button'); const magneticStrength = 50; document.addEventListener('mousemove', function(e) { const rect = btn.getBoundingClientRect(); const btnCenterX = rect.left + rect.width / 2; const btnCenterY = rect.top + rect.height / 2; const distanceX = e.clientX - btnCenterX; const distanceY = e.clientY - btnCenterY; const distance = Math.sqrt(distanceX * distanceX + distanceY * distanceY); if (distance < 200) { const strength = (200 - distance) / 200; const moveX = (distanceX / distance) * magneticStrength * strength; const moveY = (distanceY / distance) * magneticStrength * strength; btn.style.transform = `translate(${moveX}px, ${moveY}px) scale(${1 + strength * 0.1})`; btn.style.boxShadow = `${moveX}px ${moveY + 20}px 60px rgba(247, 37, 133, ${0.5 + strength * 0.3})`; } else { btn.style.transform = 'translate(0, 0) scale(1)'; btn.style.boxShadow = '0 20px 60px rgba(247, 37, 133, 0.5)'; } }); btn.addEventListener('click', function() { btn.classList.add('active'); for (let i = 0; i < 12; i++) { const line = document.createElement('div'); line.className = 'field-line'; const angle = (i * 30) * Math.PI / 180; line.style.transform = `rotate(${i * 30}deg)`; line.style.left = '50%'; line.style.top = '50%'; line.style.marginLeft = '-100px'; line.style.marginTop = '-1px'; btn.appendChild(line); setTimeout(() => line.remove(), 1000); } setTimeout(() => btn.classList.remove('active'), 1000); });
Comments
0
Want to comment?
Please
login
or
sign up
to post comments.
No comments yet
Be the first to comment on this component!
Comments 0
Want to comment?
Please login or sign up to post comments.
No comments yet
Be the first to comment on this component!