Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                <section id="container">
  <section class="dropbox" id="dropbox">
    <h4>Drop files here to upload</h4>
  </section>
</section>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  font-family: 'Lobster', cursive;
}

body, html {
  height:100%;
  background: url('https://phandroid.s3.amazonaws.com/wp-content/uploads/2014/06/kite.jpg') no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

#container{
  width:100%;
  min-height:100%;
  margin:0 auto;
  padding:0;
  overflow:auto;
}

.dropbox {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  width: 480px;
  height: 170px;
  margin: auto;
  display:inline-block;
  color: #fff;
  text-align: center;
  line-height: 170px;
  font-size: 26px;
  text-shadow: 2px 3px #333;
  border: 4px dashed #fff;
  border-radius: 12px;
  background-color: rgba(52, 73, 94, 0.75);
  transition: all .2s ease-in-out;
}

.dropbox:hover {
  width: 520px;
  height:180px;
  line-height:180px;
  cursor: pointer;
  background-color: rgba(52, 73, 94, 0.5);
}

.dropbox.dragover {
  width: 420px;
  height: 170px;
  line-height: 170px;
  cursor: pointer;
}
              
            
!

JS

              
                function init() {
  // Global variables 
  var dropbox = document.getElementById('dropbox');
  var uploadDest = 'some.php';
  var maxFiles = 2;
  //var allowedFiles = /(.*?)\.(jpeg|jpg|gif|png|pdf)$/;
  //TODO Create maxFiles var

  //TODO Limit file extensions

  //TODO create a function that displays uploded files in our html!!!
  function displayFiles() {

  }

  // AJAX function for file uploads
  function uploadFiles(files) {
    //FormData supports IE 10+ TODO falback
    var formData = new FormData();
    var xhr = new XMLHttpRequest();

    for (var i = 0; i < files.length; i++) {
      //TODO Append in php files array
      console.log('Looping trough passed data', files[i]);
    }

    //On successful upload response, parse JSON data
    //TODO handle response from php server script 
    xhr.onload = function() {
      var data = JSON.parse(this.responseText);
    }

    //Open an AJAX post request
    xhr.open('post', uploadDest);
    xhr.send(formData);
  }

  //Style dropbox on this event
  dropbox.ondragover = function() {
      this.className = 'dropbox dragover';
      return false;
    }
    //Style dropbox on this event
  dropbox.ondragleave = function() {
    this.className = 'dropbox';
    return false;
  }

  // Call uploadFiles function with arguments 
  dropbox.ondrop = function(e) {
    //Prevent default browser behaviour 
    e.preventDefault();

    this.className = 'dropbox';
    console.log(e.dataTransfer.files);
    uploadFiles(e.dataTransfer.files);
  }
}

init();
              
            
!
999px

Console