Jquery droppable

by ozzon91

HTML

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div class="c">
  <div class="area">
    <div class="inside">
      <div class="dragg"></div>
    </div>
  </div>
  <div class="area">
    <div class="inside">
      <div class="dragg"></div>
    </div>
  </div>
</div>

SCSS

.dragg {
   width: 50px;
   height: 50px;
   background: red;
}

.hov {
  background: #333 !important;
}

.c {
    
   overflow: hidden;
  
  .area {
    width: 200px;
    height: 200px;
    float: left;
    background: blue;
    margin: 10px;
    overflow: auto;
    
    .inside {
      width: 500px;
    height: 500px;
    background: tan;
    }
  }
}

JavaScript

$(function() {
 		var dragging = false;
    $( ".dragg" ).draggable({
      containment: '.c',
      helper: 'clone',
      appendTo: '.c',
      zIndex: 9999,
      start: function(e, ui) {
      	dragging = true;
        console.log(ui);
        ui.helper.prevObject.closest( ".inside" ).addClass('hov');
      	ui.helper.css('pointer-events', 'none');
      },
      stop: function(e, ui) {
      	dragging = false;
        $( ".inside" ).removeClass('hov');
      	ui.helper.css('pointer-events', '');
      },
    });
    
    $( ".inside" ).mouseenter(function() {
    		if(dragging) $(this).addClass('hov');
    }).mouseleave(function() {
    	if(dragging) $(this).removeClass('hov');
    });
 });