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 class="parent-wrapper">
  <a id="url-1" href="http://www.example.org"><span class="typer-item" id="text-1">Item 1</span></a>
  <a id="url-2" href="http://www.example.org"><span class="typer-item" id="text-2">Item 2</span></a>
  <a id="url-3" href="http://www.example.org"><span class="typer-item" id="text-3">Item 3</span></a>
</div>
              
            
!

CSS

              
                @keyframes blink-animation {
  from {
    visibility: visible;
  }
  to {
    visibility: hidden;
  }
}
@-webkit-keyframes blink-animation {
  from {
    visibility: visible;
  }
  to {
    visibility: hidden;
  }
}
body{
  background:#222;
}
.parent-wrapper{
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  max-width:800px;
  width:100%;
}
.typer-item {
  font-size:50px;
  color: white;
  display: block;
  &.js--is-animating {
    &:after {
      content: "";
      border-left: 3px solid white;
      margin-left: 1px;
      animation: blink-animation .5s steps(5, start) infinite;
      -webkit-animation: blink-animation .5s steps(5, start) infinite;
    }
  }
}
a{
  text-decoration:none;
}
              
            
!

JS

              
                /**
 *
 * @param targets - The target IDs of both the anchor tags and text wrapper. should be an array of objects [{text: "text-target-id", url: "url-target-id"}]
 * @param items - An array of items to display in each target. Should be an array of objects [{phrase: "Phrase to type", url: "url to direct visitors to"}]
 * @param args - Additional argument overrides, as an object {time_between_words: 20, typing_speed: 50}.
 * @constructor
 */
function Typer(targets, items, args) {
  this.elements = [];
  for (i = 0; i < targets.length; i++) {
    this.elements.push({
      text: document.getElementById(targets[i].text),
      url: document.getElementById(targets[i].url)
    });
    items.push(items[0]);
    items.shift();
  }
  this.phraseElement = this.elements[0].text;
  this.urlElement = this.elements[0].url;
  this.args = args;
  this.args.typing_speed = this.args.typing_speed === undefined
    ? 50
    : this.args.typing_speed;
  this.args.time_between_words = this.args.time_between_words === undefined
    ? 20
    : this.args.time_between_words;
  this.waitTimer = 0;
  this.phrases = items;
  this.word = {
    current: [],
    currentLetter: "",
    length: 0
  };
  this.interval = false;

  /**
   * Selects the next phraseElement to display the content.
   */
  this.selectNextElement = function() {
    this.elements.push(this.elements[0]);
    this.elements.shift();
    this.phraseElement = this.elements[0].text;
    this.urlElement = this.elements[0].url;
  };

  /**
   * Grabs the next item from the phrases array, and rearranges the array
   * @returns {*}
   */
  this.getNextPhrase = function() {
    this.phrases.push(this.phrases[0]);
    this.phrases.shift();
    this.word.current = this.phrases[0].phrase.split("");
    this.word.length = this.word.current.length;
    this.urlElement.setAttribute("href", this.phrases[0].url);
    return this.word.current;
  };

  /**
   * Types the next letter in the current word
   * @returns {*}
   */
  this.typeLetter = function() {
    this.word.currentLetter = this.word.current[0];
    this.word.current.shift();
    this.phraseElement.innerHTML =
      this.phraseElement.innerHTML + this.word.currentLetter;
    if (!this.hasLetters()) {
      this.waitTimer = this.args.time_between_words;
      this.phraseElement.classList.remove("js--is-animating");
      this.selectNextElement();
    }
  };

  /**
   * Checks to see if the current word has any letters to display
   * @returns {boolean}
   */
  this.hasLetters = function() {
    return this.word.current.length > 0;
  };

  /**
   * Deletes a letter from the end of the current phrase
   */
  this.deleteLetter = function() {
    if (this.phraseElement.innerHTML.length > 0) {
      this.phraseElement.innerHTML = this.phraseElement.innerHTML.substring(
        0,
        this.phraseElement.innerHTML.length - 1
      );
    } else {
      this.getNextPhrase();
    }
  };

  /**
   * Sets the type interval for the function
   * @param self
   */
  this.typeInterval = function(self) {
    if (self.waitTimer === 0) {
      self.phraseElement.classList.add("js--is-animating");
      if (self.hasLetters()) {
        self.typeLetter();
      } else {
        self.deleteLetter();
      }
    } else {
      self.waitTimer--;
    }
  };

  /**
   * Run this in the JS to run the timer
   */
  this.type = function() {
    typeObject = this;
    this.interval = setInterval(function() {
      typeObject.typeInterval(typeObject);
    }, this.args.typing_speed);
  };
}

//In my personal version, this data is passed from an external source.


var typer = new Typer(
  [
    { text: "text-1", url: "url-1" },
    { text: "text-2", url: "url-2" },
    { text: "text-3", url: "url-3" }
  ],
  [
    {
      phrase: "Instagram Stories",
      url: "http://www.instagram.com"
    },
    {
      phrase: "Tweet Chats",
      url: "http://www.twitter.com"
    },
    {
      phrase: "Stories",
      url: "/blog"
    },
    {
      phrase: "Podcasts",
      url: "http://www.stitcher.com"
    },
    {
      phrase: "Snapchat",
      url: "http://www.snapchat.com"
    }
  ],
  {
    /*Arg overrides can go here*/
  }
);
typer.type();

              
            
!
999px

Console