PLUGINS
MODULES
PolyDev
BLOG
Dự án
Ý tưởng & tính năng
Phần Mềm
POD
Tài Liệu Hướng Dẫn
API’s
Tiếng Việt
English
Plugins
PolyDev
Hiệu ứng nút Add To Cart
21/09/2024
/
thankzone
HTML
CSS
JS
RESULT
HTML
Dracula
Yonce
Monokai
Material
Darcula
Solarized
Eclipse
Midnight
Ambiance
Cobalt
Neo
Twilight
XQ Dark
XQ Light
Zenburn
Thêm vào Giỏ Hàng
Cảm ơn bạn!
CSS
Dracula
Yonce
Monokai
Material
Darcula
Solarized
Eclipse
Midnight
Ambiance
Cobalt
Neo
Twilight
XQ Dark
XQ Light
Zenburn
/* General body styling */ body { margin: 0; padding: 0; height: 100vh; display: flex; justify-content: center; align-items: center; background-color: #ebe8ff; } /* Button styling */ .btn-cart { position: relative; padding: 10px; width: 300px; height: 60px; border: 0; border-radius: 10px; background-color: #d4344e; outline: none; cursor: pointer; color: #fff; transition: .3s ease-in-out; overflow: hidden; } .btn-cart:hover { background-color: #d80d2e; } .btn-cart:active { transform: scale(.9); } /* Cart and box icons */ .icon-cart { position: absolute; z-index: 2; top: 50%; left: -10%; font-size: 2em; transform: translate(-50%, -50%); } .icon-box { position: absolute; z-index: 3; top: -20%; left: 52%; font-size: 1.2em; transform: translate(-50%, -50%); } /* Button text styling */ .btn-cart span { position: absolute; z-index: 3; left: 50%; top: 50%; font-size: 1.2em; color: #fff; transform: translate(-50%, -50%); } /* Add To Cart text */ .text-add { opacity: 1; } /* Thank You! text */ .text-added { opacity: 0; } /* Animation classes */ .btn-cart.clicked .icon-cart { animation: cartMove 1.5s ease-in-out forwards; } .btn-cart.clicked .icon-box { animation: boxMove 1.5s ease-in-out forwards; } .btn-cart.clicked .text-add { animation: fadeOutText 1.5s ease-in-out forwards; } .btn-cart.clicked .text-added { animation: fadeInText 1.5s ease-in-out forwards; } /* Keyframe animations */ @keyframes cartMove { 0% { left: -10%; } 40%, 60% { left: 50%; } 100% { left: 110%; } } @keyframes boxMove { 0%, 40% { top: -20%; } 60% { top: 40%; left: 52%; } 100% { top: 40%; left: 112%; } } @keyframes fadeOutText { 0% { opacity: 1; } 20%, 100% { opacity: 0; } } @keyframes fadeInText { 0%, 80% { opacity: 0; } 100% { opacity: 1; } }
JavaScript
Dracula
Yonce
Monokai
Material
Darcula
Solarized
Eclipse
Midnight
Ambiance
Cobalt
Neo
Twilight
XQ Dark
XQ Light
Zenburn
// Select all buttons with the class .btn-cart const cartButtons = document.querySelectorAll('.btn-cart'); // Add click event to each button cartButtons.forEach(button => { button.addEventListener('click', handleCartClick); }); // Function to handle cart button click function handleCartClick() { let button = this; button.classList.add('clicked'); }
Preview: Hiệu ứng nút Add To Cart
By me a coffee
<body>
@polyxgo
PolyXGO