Component location
Files are located in src/components/forms/addtocart. Inside you’ll find:
- JS file with add-to-cart logic and optional animation.
- HTML example snippet.
- SCSS file for styling the cart UI and animation helpers.
Cart counter
Add data-anim-addtocart to the element that displays the cart quantity.
The component will update this value automatically.
<div class="cart">
<span class="cart__quantity" data-anim-addtocart>0</span>
</div>
Add to cart button
Add data-anim-addtocart-button to your “Buy / Add to cart” button.
On click, the cart counter will increase.
<button type="button" data-anim-addtocart-button>Add to cart</button>
Product wrapper & quantity
To enable product-level features (quantity and image animation), wrap the product with
data-anim-addtocart-product.
<div data-anim-addtocart-product class="product">
...
<button type="button" data-anim-addtocart-button>Add to cart</button>
</div>
Quantity via input
Add data-anim-addtocart-quantity to an <input> that controls
quantity.
The entered value will be used when adding items.
<div data-anim-addtocart-product class="product">
...
<input data-anim-addtocart-quantity autocomplete="off" type="text" name="form[]" value="1">
<button type="button" data-anim-addtocart-button>Add to cart</button>
</div>
Quantity via “Quantity” component
You can also use the template’s Quantity component and still connect the value via
data-anim-addtocart-quantity.
<div data-anim-addtocart-product class="product">
...
<div data-anim-quantity class="quantity">
<button data-anim-quantity-minus type="button" class="quantity__button quantity__button--minus"></button>
<div class="quantity__input">
<input
data-anim-addtocart-quantity
data-anim-quantity-value
autocomplete="off"
type="text"
name="form[]"
value="1">
</div>
<button data-anim-quantity-plus type="button" class="quantity__button quantity__button--plus"></button>
</div>
<button type="button" data-anim-addtocart-button>Add to cart</button>
</div>
Fly-to-cart image animation
To animate the product image flying into the cart, add data-anim-addtocart-image
to the product’s <img>.
<div data-anim-addtocart-product class="product">
...
<img src="..." data-anim-addtocart-image alt="Image">
<button type="button" data-anim-addtocart-button>Add to cart</button>
</div>
Animation speed
To control animation duration, set a value (milliseconds) on
data-anim-addtocart-image. Default is 500ms.
<img src="..." data-anim-addtocart-image="1000" alt="Image">
Download
Build e-commerce UI faster: cart counter, quantity control, and a clean “fly to cart” animation. Download the template and start shipping today.