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

              
                <button id="action">Make the letters explode</button>
<div class="stage">
<svg id="demo" xmlns="http://www.w3.org/2000/svg" width="2000" height="1000" viewBox="0 0 2000 1000">
<rect id="background" x="0" y="0" width="2000" height="1000" fill="#000" />
</svg>
</div>
<div class="credits">
  <p>Another exciting SVG quick tip demo from PointC</p>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  height: 100vh;
  width: 100%;
  padding: 0;
  margin: 0;
  overflow: hidden;
  background: #000;
  color: white;
  font-family: "Signika", sans-serif;
}

.stage {
  display: flex;
  align-content: center;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  position: relative;
  z-index: 1;
}

#demo {
  width: auto;
  height: auto;
  max-height: 82%;
  max-width: 96%;
  font-weight: 700;
  overflow: visible;
}

#action {
  padding: 10px;
  font-size: 0.875em;
  margin: 10px;
  cursor: pointer;
  font-weight: 700;
  font-family: "Roboto", sans-serif;
  position: absolute;
  z-index: 10;
}

.credits {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 100px;
  width: 100%;
  background: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/314556/codepenAvatar.png")
    20px bottom no-repeat;
  background-size: contain;
  z-index: 8;
}

.credits p {
  font-family: "Roboto", sans-serif;
  position: absolute;
  bottom: 0;
  left: 100px;
  line-height: 1.5;
  margin: 0;
  font-size: 0.875em;
}

              
            
!

JS

              
                console.clear();
document.addEventListener("DOMContentLoaded", function(event) {
window.onload = function() {
var textArray = ["KABOOM!!", "EXPLODE!", "KAPOW!!", "GreenSock", "BLAMMO!", "BOOM!!!!"];
var toggle = 0;
var colors = ["#61ac27", "#e87647", "#ff718d", "#e5dc2f", "#3ba4c6", "#af2acc"];
var fontSize = 300; // base size for font
var fontVary = 100; // how much bigger or smaller the font could be than the base
var svgns = "http://www.w3.org/2000/svg";
var demo = document.querySelector("#demo");
var demoSize = demo.getBBox();
var dur = 1;

function createText() {
  var theText = textArray[Math.floor(Math.random() * textArray.length)];
  var leftPos = 0;

  for (let i = 0; i < theText.length; i++) {
    var text = document.createElementNS(svgns, "text");
    var newColor = Math.floor(Math.random() * colors.length);
    text.setAttributeNS(null, "font-size", random(fontSize - fontVary, fontSize + fontVary));
    demo.appendChild(text);
    text.textContent = theText.charAt(i);
    var theSize = text.getBBox();
    TweenMax.set(text, {
      attr: {
        y: -theSize.y + demoSize.height / 2 - theSize.height / 2, // center vertically
        x: leftPos, // line up each character next to the previous one
        fill: colors[newColor]
      },
        stroke:"#fff",
        strokeWidth:2,
        opacity: 0
  });
    leftPos += theSize.width; // x position of next character 
}

    targets = document.querySelectorAll("text");
    var centerW = demoSize.width / 2 - leftPos / 2;
    TweenMax.set(targets, { attr: { x: "+=" + centerW } });// center word horizontally
    TweenMax.to(targets, 0.5, {opacity:1, ease:Linear.easeNone, onComplete:function() {
    toggle = 1;
}});
}

// kaboom button
document.querySelector("#action").addEventListener("click", doCoolStuff);
function doCoolStuff() {
  if (toggle == 1) {
    toggle = 0;
    for (let i = 0; i < targets.length; i++) {
    TweenMax.to(targets[i], dur, {
      x: random(-2000, 2000),
      y: random(-1000, 1000),
      rotation: random(-720, 720),
      scale: 0,
      transformOrigin: "center center",
      onComplete:onComplete
    });
  }
  TweenLite.delayedCall(dur*1.01, createText);
  }
}

function random(min, max) {
  return min + (max - min) * Math.random();
}

function onComplete() {
  demo.removeChild(this.target);
}

createText();
  
      }; 
});

              
            
!
999px

Console