Fit borders in HTML

0

In my program:

$(document).ready(function(){

	var $lista1 = $('#lista1'), $lista2 = $('#lista2');
	// lista 1
	$('li',$lista1).draggable({
		revert: 'invalid',		
		helper: 'clone',		
		cursor: 'move'
	});
	$lista1.droppable({
		accept: '#lista2 li',
		drop: function(ev, ui) {
			deleteLista2(ui.draggable);
		}
	});
	/* lista2 */
	$('li',$lista2).draggable({
		revert: 'invalid',
		helper: 'clone',	
		cursor: 'move'
	});
	$lista2.droppable({
		accept: '#lista1 > li',
		drop: function(ev, ui) {
			deleteLista1(ui.draggable);		
		}
	});
	// listas	
	function deleteLista1($item) {
		$item.fadeOut(function() {
			$($item).appendTo($lista2).fadeIn();;
		});
		$item.fadeIn();
	}
	function deleteLista2($item) {
		$item.fadeOut(function() {			
			$item.appendTo($lista1).fadeIn();
		});
	}

});
body,td,th {
	color: #333333;
}
#lista1, #lista2 {
	width:200px;
	border:1px solid #990000;
	height:auto;
	float:left;
	margin-right:5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div id="demo-frame">
<ul id="lista1" class="gallery">
	<li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
</ul>
<ul id="lista2">
	<li>Item5</li>
    <li>Item6</li>
    <li>Item7</li>
</ul>
</div>

You can move the rows from one list to another, but what I want is that the edge has a space, because when you move an item and pass it to another list the edge shrinks and the problem is that when does not have any item, a list that stays as a line and it's hard to enter an item.

Please, I need your help.

    
asked by Reinos Ric 08.08.2017 в 22:37
source

1 answer

1

It is not necessary to do it with javascript, just put a min-height to div so that it does not disappear when you run out of elements.

$(document).ready(function() {

  var $lista1 = $('#lista1'),
    $lista2 = $('#lista2');
  // lista 1
  $('li', $lista1).draggable({
    revert: 'invalid',
    helper: 'clone',
    cursor: 'move'
  });
  $lista1.droppable({
    accept: '#lista2 li',
    drop: function(ev, ui) {
      deleteLista2(ui.draggable);
    }
  });
  /* lista2 */
  $('li', $lista2).draggable({
    revert: 'invalid',
    helper: 'clone',
    cursor: 'move'
  });
  $lista2.droppable({
    accept: '#lista1 > li',
    drop: function(ev, ui) {
      deleteLista1(ui.draggable);
    }
  });
  // listas	
  function deleteLista1($item) {
    $item.fadeOut(function() {
      $($item).appendTo($lista2).fadeIn();;
    });
    $item.fadeIn();
  }

  function deleteLista2($item) {
    $item.fadeOut(function() {
      $item.appendTo($lista1).fadeIn();
    });
  }

});
body,
td,
th {
  color: #333333;
}

#lista1,
#lista2 {
  width: 200px;
  border: 1px solid #990000;
  height: auto;
  float: left;
  margin-right: 5px;
  min-height: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet" />

<div id="demo-frame">
  <ul id="lista1" class="gallery">
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
  </ul>
  <ul id="lista2">
    <li>Item5</li>
    <li>Item6</li>
    <li>Item7</li>
  </ul>
</div>
    
answered by 09.08.2017 / 02:11
source