<div class="product">
	<img src="http://waarmedia.com/english/file/2019/04/nuts.jpg" alt="" class="product-img">
	<span class="product-name">Nuts</span>
	<div class="but-wrap">
		<div class="addToCart">add to cart</div>
	</div>
</div>

<div class="cart">Cart</div>
body{
  background: #fff;
  padding: 20px;
  font-family: Helvetica;
}
.cart{
  position: absolute;
  display: table;
  width: auto;
  height: auto;
  box-sizing: border-box;
  background: #C94449;
  border-radius: 5px;
  padding: 8px 14px;
  font-size: 15px;
  color: #fff;
  top: 10px;
  right: 10px;
}
.product{
  position: relative;
  display: table;
  width: 300px;
  height: auto;
  box-sizing: border-box;
  padding: 10px;
  border: 1px solid #262626;
  border-radius: 10px;
}
.product-img{
  position: relative;
  display: inline-block;
  width: 100%;
  height: auto;
  box-sizing: border-box;
  margin-bottom: 10px;
}
.product-name{
  position: relative;
  display: inline-block;
  width: 100%;
  height: auto;
  text-align: center;
  margin-bottom: 10px;
}
.but-wrap{
  position: static;
  display: inline-block;
  width: 100%;
  height: auto;
}
  .addToCart{
    position: relative;
    display: table;
    width: auto;
    height: auto;
    box-sizing: border-box;
    background: #FF0000;
    border-radius: 5px;
    padding: 8px 14px;
    font-size: 15px;
    color: #fff;
    margin: auto;
    cursor: pointer;
  }
$('.addToCart').click(function(e){
  var butWrap = $(this).parents('.but-wrap');
  butWrap.append('<div class="animtocart"></div>');
  $('.animtocart').css({
    'position' : 'absolute',
    'background' : '#FF0000',
    'width' :  '25px',
    'height' : '25px',
    'border-radius' : '100px',
    'z-index' : '9999999999',
    'left' : e.pageX-25,
    'top' : e.pageY-25,
  });
	var cart = $('.cart').offset();
	$('.animtocart').animate({ top: cart.top + 'px', left: cart.left + 'px', width: 0, height: 0 }, 800, function(){
    $(this).remove();
  });
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js