Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<div id="arrastrables">
<div class="arrastrable" draggable="true" >
    <img src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/book_blue.jpg" />
</div>
  
<div class="arrastrable" draggable="true" >
    <img src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/book_white.jpg" />
</div>
  
  <div class="arrastrable" draggable="true" >
    <img src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/book_orange.jpg" />
</div>
  
  <div class="arrastrable" draggable="true" >
    <img src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/book_red.jpg" />
</div>
</div>

<div id="zonasDeSoltar">
<div class="zona-de-soltar"></div>
<div class="zona-de-soltar"></div>
<div class="zona-de-soltar"></div>
<div class="zona-de-soltar"></div>
</div>

              
            
!

CSS

              
                #zonasDeSoltar, #arrastrables{display:flex;}  
#arrastrables div{margin:10px 17px 0 10px;}
.arrastrable {
    flex:0 0 100px;
    height: 160px;
    text-align: center;
    background: white;
    border:1px solid;
 
  }

  .zona-de-soltar {
    flex:0 0 100px;
    height: 160px;
    background: blueviolet;
    padding: 10px;
    margin:10px 10px 0 0 ;
  }
              
            
!

JS

              
                 var elementoArrastrado;

 
  document.addEventListener("drag", function( event ) {
  //console.log("drag")
  }, false);


  document.addEventListener("dragstart", function( event ) {
    // guarda información acerca del objeto arrastrado
    event.dataTransfer.setData('text/plain',null)
      // guarda una referéncia del elemento arrastrado
      elementoArrastrado = event.target;
      // cambia la opacidad del elemento a medio transparente
      event.target.style.opacity = .5;
  }, false);


  document.addEventListener("dragend", function( event ) {
      // reestablece el valor de la opacidad
      event.target.style.opacity = 1;
  }, false);

 
  document.addEventListener("dragover", function( event ) {
      // previene el comportamiento por defecto del elemento arrastrado
     event.preventDefault();
  }, false);

  document.addEventListener("dragenter", function( event ) {
      // comprueba si el event.target es una zona de soltar  
      if ( event.target.className == "zona-de-soltar" ) {
        // y di lo és cambia el color de fondo
          event.target.style.background = "purple";
      }

  }, false);

  document.addEventListener("dragleave", function( event ) {
      // comprueba si el event.target es una zona de soltar  
      if ( event.target.className == "zona-de-soltar"  ) {
        // y si lo és, reestablece el valor inicial
          event.target.style.background = "";
      }
  }, false);

  document.addEventListener("drop", function( event ) {
      // Si el elemento arrastrado es un link, este se abre en una nueve página.
      // Para que esto no pase hay que utilizar: 
      event.preventDefault();
      // comprueba si el event.target es una zona de soltar
      if ( event.target.className == "zona-de-soltar"  ) {
          // reestablece el valor inicial para el background
          event.target.style.background = "";
          // elimina el elemento arrastrado del del elemento padre
          elementoArrastrado.parentNode.removeChild( elementoArrastrado );
          // y lo agrega al elemento de destino
          event.target.appendChild( elementoArrastrado );
      }
    
  }, false);





              
            
!
999px

Console