2.0.1 • Published 5 months ago

cartflow v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

CartFlow

npm version Total Downloads License

CartFlow is a lightweight, modern JavaScript library to animate items moving to a shopping cart. It supports Node.js, browser environments, and UMD/ES module formats.

Features

  • Smooth animations for "Add to Cart" interactions.

  • Optional sound effect support with type validation and warnings for unsupported types.

  • Optional cart "shake" effect after adding an item.

  • Fully customizable via configuration options.

  • Works seamlessly in modern browsers and Node.js environments.

  • Callbacks with relevant elements for better integration.

  • Uses GSAP for animations with a fallback mechanism if GSAP is unavailable.

Installation

Using npm (for Node.js and bundlers like Webpack, Vite, or Rollup):

npm install cartflow

Using a <script> tag (for browsers):

<script src="CartFlow.js"></script>

NodeJs

const CartFlow = require('cartflow');

Usage

const animation = new CartFlow({
    cartSelector: ".shopping-cart",
    buttonSelector: ".add-to-cart",
    onComplete: (item) => {
        console.log("Item successfully animated to the cart!", item);
    },
    onCartShake: (cart) => {
        console.log("Cart shake effect completed!", cart);
    },
    soundEffect: "click-sound.mp3",
  });

See online Demo

Configuration Options

OptionTypeDefaultDescription
cartSelectorstring.shopping-cartCSS selector for the shopping cart element.
buttonSelectorstring.add-to-cartCSS selector for the "Add to Cart" buttons.
itemSelectorstring.itemCSS selector for the item container.
imageSelectorstringimgCSS selector for the item's image.
animationDurationnumber1000Duration of the animation in milliseconds.
easingstringease-in-outEasing function for the animation.
shakeEffectbooleantrueEnable or disable the cart shake effect.
soundEffectstring or AudionullURL or Audio object for a sound effect.
onCompletefunctionnullCallback function after the animation completes, receives the affected item element.
onCartShakefunctionnullCallback function after the cart shake effect, receives the cart element.

Browser & Nodejs Compatibility

ChromeFirefoxSafariOperaEdgeNodejs
Latest ✔Latest ✔Latest ✔Latest ✔Latest ✔Latest ✔

Contributing

Feel free to submit issues or pull requests to improve the package. Contributions are welcome!

License

This package is open-source software licensed under the MIT license.