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 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

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

              
                <div class="container"></div>
              
            
!

CSS

              
                .container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  user-select: none;
  pointer-events: none;
}
img {
  position: absolute;
}
              
            
!

JS

              
                // Array with all our images
var allImages = [
  'https://www.asso-cocktail.fr/misc/image/logo-appli/PIM.png',
  'https://upload.wikimedia.org/wikipedia/fr/b/b2/Designer.png',
  'https://pbs.twimg.com/profile_images/631079713671397376/l_RaFUu3_400x400.jpg'
]
// The counter
var count = 0
// Wait for the DOM to be loaded
document.addEventListener("DOMContentLoaded", function () {
  // Select the container
  var container = document.querySelector('.container')
  // Generate a random number
  var randomNumber = function() {
    return Math.floor(Math.random() * (allImages.length));
  }
  // Place the image generated by loadImage function
  var placeImage = function(x, y, newImage) {
    // Wait for the image to be loaded
    newImage.addEventListener("load", function() {
      // Put the new image into the DOM
      container.append(newImage)
      // Select the new image by his id attribute
      var theImage = document.querySelector('[id="' + count + '"]')
      // Center the image on mouse pointer
      theImage.style.left = x - (theImage.width/2) + 'px'
      theImage.style.top = y - (theImage.height/2) + 'px'
      // Increment the counter
      count++
    })
  }
  // Create a new image
  var loadImage = function(x, y) {
    var newImage = new Image()
    // Set the source
    newImage.src = allImages[randomNumber()]
    // Set the attribute Id
    newImage.setAttribute('id', count)
    // Place it
    placeImage(x, y, newImage)
  }
  // Listen to the mouseup event                             
  document.addEventListener('click', function (event) {
    // Get the mouse position
    var x = event.clientX
    var y = event.clientY
    // load image
    loadImage(x, y)
  }, false);
})
              
            
!
999px

Console