JSFiddle - React, Tailwind, and code Playground

by antishok

HTML

<p>Click on parts of the image</p>
<div><img src="http://unsplash.it/500/300" alt="image" class="image"></div>
<div class="hidden">
  <span class="product-set__pin">
     <span>x</span>
  <img src="http://unsplash.it/20" alt="hey" class="" />
  </span>

  <div class="product-set__products">
    <div class="list list--pointy-top">
      <div class="list__control">
        <h4>Product</h4>
        <input type="text" class="form__input hideseek" data-list=".js-collectionProducts">
      </div>
      <ul class="js-collectionProducts list__subscroll scroll">
        <li class="list__item">
          <input type="radio" name="pinnedprod" class="pinnedprod" value="1"><input type="radio" name="pinnedprod" class="pinnedprod" value="2"> Stuff here</li>
      </ul>
    </div>
  </div>
</div>

CSS

.product-set__pin {
  display: inline-block;
  color:white;
}

.product-set__pin > span {
  background: red;
}

.hidden {
  display: none
}


/*---------------------------------------*\
 List
\*---------------------------------------*/


/* line 424  */

.list {
  list-style-type: none;
  max-height: 300px;
  width: 300px;
  margin: 0;
  padding: 0;
  background: #fff;
  border: solid thin #ccc;
  border-top: solid 8px #ccc;
  border-bottom: solid 8px #ccc;
  border-radius: 5px;
}


/* line 434  */

.list--long {
  max-height: none;
}


/* line 438  */

.list--pointy-top::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 4px;
  width: 10px;
  height: 10px;
  background: #ccc;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
}


/* line 449 */

.list__item {
  padding: 5px 10px;
}


/* line 451 */

.list__item:not(:last-child) {
  border-bottom: solid thin #ccc;
}


/* line 455 */

.list__control {
  padding: 5px 10px;
  background: #ddd;
}


/* line 458 */

.list__control h4 {
  margin: 5px 0;
}


/* line 462 */

.list__subscroll {
  list-style-type: none;
  margin: 0;
  padding: 0;
  max-height: calc(300px - 90px);
}

JavaScript

var counter = 0;
var origPin = $('.product-set__pin');
var currentPin;

$(document).on('click', '.image', function(e) {
  var imageParent = $(this).parent();
  imageParent.css('position', 'relative');
  mouseX = e.pageX - imageParent.offset().left;
  mouseY = e.pageY - imageParent.offset().top;
  counter++;
  var pin = origPin.clone(),
    products = $('.product-set__products'),
    pinStyles = {
      position: 'absolute',
      left: mouseX + 'px',
      top: mouseY + 'px'
    },
    productStyles = {
      position: 'absolute',
      left: mouseX + 'px',
      top: mouseY + 35 + 'px'
    };
  pin.css(pinStyles);
  pin.attr('data-index', counter);
  products.css(productStyles);
  imageParent.append(pin);
  imageParent.append(products);
  currentPin = pin;
});
$(document).on('click', '.product-set__pin > span', function() {
  $(this).parent().remove();
});

$(document).on('change', '.pinnedprod', function() {
	currentPin.append(this.value)  
});