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

              
                <p>Try interacting with the boring boxes</p>
<boring-box id="box1"></boring-box>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  user-select: none;
}

boring-box {
  display: inline-flex;
  width: 150px;
  height: 75px;
  margin: 10px;
  color: #fff;
  padding: 10px;
  border: 2px solid rgba(0,0,0,0);
  opacity: 0;
}

p {
  margin: 10px;
}
              
            
!

JS

              
                console.clear();

class BoringBox {
  
  text = "Foo";
  backgroundColor = "#1e90ff";
  
  constructor(element, options) {
    
    var isObject = (typeof element === "object");
    var isElement = (isObject && element.nodeType === 1);
    
    if (typeof options === "undefined" && isObject && !isElement) {
      options = element;
      element = undefined;
    }
    
    if (typeof element === "string") {
      this.element = document.querySelector(element) || document.createElement("boring-box");
    } else if (isElement) {
      this.element = element;
    } else {
      this.element = document.createElement("boring-box");
    }
       
    if (options) {
      Object.assign(this, options);
    }
    
    this.draggable = new Draggable(this.element, {
      allowEventDefault: true,
      throwProps: true
    });
      
    TweenLite.set(this.element, { backgroundColor: this.backgroundColor, text: this.text });
    
    this.transform = this.element._gsTransform;
    this.hoverAnimation = TweenLite.to(this.element, 0.25, { borderColor: "rgba(0,0,0,0.25)", opacity: 1, paused: true });
    this.fadeAnimation = TweenLite.to(this.element, 0.5, { opacity: 0.8, paused: true, onComplete: () => this.bindEvents() });    
  }
  
  bindEvents() {
    this.fadeAnimation.vars.onComplete = null;
    this.element.addEventListener("mousedown", this.onMouseDown.bind(this));
    this.element.addEventListener("mouseenter", this.onMouseEnter.bind(this));
    this.element.addEventListener("mouseleave", this.onMouseLeave.bind(this));
  }
  
  onMouseDown() {
    var rotation = Math.round((this.transform.rotation + 180) / 180) * 180;
    TweenLite.to(this.element, 0.5, { rotation });
  }
  
  onMouseEnter() {
    this.hoverAnimation.play();
    return this;
  }
  
  onMouseLeave() {
    this.hoverAnimation.reverse();
    return this;
  }
  
  fadeIn() {
    this.fadeAnimation.play();
    return this;
  }
  
  fadeOut() {
    this.fadeAnimation.reverse();
    return this;
  }
  
  resetPosition() {
    
    if (this.transform.x || this.transform.y || this.transform.rotation) {
      TweenLite.to(this.element, 1, { x: 0, y: 0, rotation: 0 });
    }    
    return this;
  }
  
  appendTo(parent) {
    parent.appendChild(this.element);
    return this;
  }
}

var box1 = new BoringBox("#box1");
var box2 = new BoringBox({ text: "YUP!!!" });
var box3 = new BoringBox(document.createElement("boring-box"), { text: "Slappy", backgroundColor: "#673ab7"});

var boringBoxes = [box1, box2, box3];

boringBoxes.forEach((box, i) => {
  
  if (!box.element.parentNode) {
    box.appendTo(document.body);
  }
  
  TweenLite.delayedCall(i * 0.3, () => {
    box.fadeIn();
  }); 
  
  console.log("BOX", box);
});


















































































































// http://www.cupcakeipsum.com/

var words = "Cupcake ipsum dolor sit amet tootsie roll toffee cookie chupa chups. Jelly cheesecake muffin chocolate bar chocolate bar candy canes. Sesame snaps I love candy canes jelly croissant powder chupa chups tiramisu chupa chups. Cheesecake cupcake liquorice candy macaroon chocolate cheesecake cake. Sweet liquorice danish gingerbread. Tart caramels sesame snaps halvah sweet roll. I love chocolate cake marshmallow I love cookie. Pie sugar plum jelly cotton candy brownie. Sugar plum tiramisu gummi bears sweet roll marzipan. Fruitcake liquorice gummi bears. Dragée bear claw I love chocolate liquorice cookie liquorice wafer carrot cake. Chocolate bar lollipop jelly soufflé jelly beans jujubes cake chupa chups. I love sesame snaps bonbon ice cream liquorice cupcake croissant candy canes. Cheesecake caramels apple pie cotton candy liquorice sweet roll chocolate bar. Lemon drops icing bonbon chocolate bar chocolate cake candy ice cream liquorice toffee. Bear claw biscuit oat cake muffin muffin sweet roll. Jelly macaroon jelly beans jelly-o cookie oat cake. Jelly-o sweet roll tiramisu sweet roll. Lollipop chupa chups bear claw I love powder chocolate cake croissant cookie cotton candy. Jelly I love wafer chupa chups pudding sweet soufflé cake donut. Liquorice croissant cotton candy lollipop. Topping brownie candy jujubes. I love liquorice dessert cookie. Cupcake bear claw I love bonbon. I love lemon drops dessert sweet tart dessert I love brownie gingerbread.".replace(/\./g, "").split(" ");

var requestId = null;

document.addEventListener("click", addSomeMoreBoringBoxesBecauseThisIsReallyBoring, true);
window.addEventListener("resize", () => {
  if (!requestId) {
    requestId = requestAnimationFrame(resetBoxes);
  }
});

function addSomeMoreBoringBoxesBecauseThisIsReallyBoring() {
  
  document.removeEventListener("click", addSomeMoreBoringBoxesBecauseThisIsReallyBoring, true);
  
  for (var i = 0; i < words.length; i++) {
    
    var box = new BoringBox({
      backgroundColor: Math.random() * 0xffffff,
      text: words[i]
    });
    
    addDelayedBox(box, i * 0.1);
  }  
}

function addDelayedBox(box, delay) {
  
  TweenLite.delayedCall(delay, () => {    
    boringBoxes.push(box);
    box.appendTo(document.body);
    box.fadeIn();
  });
}

function resetBoxes() {
  
  for (var i = 0; i < boringBoxes.length; i++) {
    boringBoxes[i].resetPosition();
  }
  
  requestId = null;
}
              
            
!
999px

Console