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

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Luis Unlimited</title>
    <link rel="stylesheet" href="./style.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
</head>
<body>
    <div class="container">
        <h1>Need a <span class="txt-type" data-wait="2500" data-words='["Website?", "Designer?", "Photographer?"]'></span><i class="fas fa-pencil-alt"></i></h1>
        <h2><a href="https://www.luisunlimited.com/" class="author">Luis Unlimited</a> is your solution!</h2>
    </div>
    


    <script src="./typingScript.js"></script>
</body>
</html>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Fredericka+the+Great');

body {
    font-family: 'Fredericka the Great', cursive;
    height: 100vh;
    background-color: rgb(241, 200, 13);
    color: rgb(73, 66, 66);
    overflow: hidden;
}
.container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    padding: 0 3rem;
}
h1,h2 {
    font-weight: 200;
    margin: 0.4rem;
}
h1 {
    font-size: 3.5rem;
}
h2 {
    font-size: 2rem;
    color:rgb(73, 66, 66);
}
.author {
    color: rgb(180, 0, 75);
    text-decoration: none;
}

a:hover {
    color: rgb(23, 77, 32);
}

.fas {
    color: rgb(0, 0, 0);
    font-size: 3rem;
   /*  background-color: green; conditional */
    margin: 0px;
    padding: 0px;
    /*****
    animation-name: erasing;    
    animation-duration: 3s;
    ***/
}
/**** this is the Pencil Erasing animation****/
.erasing-animation {
    animation-name: erasing;
    animation-duration: 1.8s;
}

@keyframes erasing {
    0% {transform: rotate(0deg);}
    10% {transform: rotate(180deg);}
    60% {transform: rotate(180deg);}
    70% {transform: rotate(0deg);}
    100% {transform: rotate(0deg);}
} 
    
/***this is the pencil writing animation*****/
.writing-animation {
    animation-name: writting;    
    animation-duration: 4s; 
}

@keyframes writting {
    0%  {transform: translate(0px,0px);}
    2%  {transform: translate(30px,-40px);}
    4%  {transform: translate(0px,0px);}
    6%  {transform: translate(30px,-40px);}
    8% {transform: translate(0px,0px);}
    10% {transform: translate(30px,-40px);}
    12% {transform: translate(0px,0px);}
    14% {transform: translate(30px,-40px);}
    16% {transform: translate(0px,0px);}
    18% {transform: translate(30px,-40px);}
    20% {transform: translate(0px,0px);}
    22% {transform: translate(30px,-40px);}
    24% {transform: translate(0px,0px);}
    26% {transform: translate(30px,-40px);}
    28% {transform: translate(0px,0px);}
    30% {transform: translate(30px,-40px);}
    32% {transform: translate(0px,0px);}
    34% {transform: translate(30px,-40px);}
    36% {transform: translate(0px,0px);}
    38% {transform: translate(30px,-40px);}
    40% {transform: translate(0px,0px);}
    42% {transform: translate(30px,-40px);}
    44% {transform: translate(0px,0px);}
    46% {transform: translate(30px,-40px);}
    48% {transform: translate(0px,0px);}
    50% {transform: translate(30px,-40px);}
    52% {transform: translate(0px,0px);}
    54% {transform: translate(30px,-40px);}
    56% {transform: translate(0px,0px);}
    58% {transform: translate(30px,-40px);}
    60% {transform: translate(0px,0px);}
    62% {transform: translate(30px,-40px);}
    64% {transform: translate(0px,0px);}
    66% {transform: translate(30px,-40px);}
    68%{transform: translate(0px,0px);}
  
    70% {transform: translate(30px,-40px);}
    72% {transform: translate(0px,0px);}
    74% {transform: translate(30px,-40px);}
    76% {transform: translate(0px,0px);}
    78% {transform: translate(30px,-40px);}
    80% {transform: translate(0px,0px);}
    82% {transform: translate(30px,-40px);}
    84% {transform: translate(0px,0px);}
    86% {transform: translate(30px,-40px);}
    88% {transform: translate(0px,0px);}
    90% {transform: translate(30px,-40px);}
    92% {transform: translate(0px,0px);}
    94% {transform: translate(30px,-40px);}
    96% {transform: translate(0px,0px);}
    98% {transform: translate(30px,-40px);}
    100% {transform: translate(0px,0px);}
    
    
}

@media(min-width: 1200px){
    h1 {
        font-size: 5rem;
    }
    .fas {
        font-size: 5rem;
    }
}
@media(max-width: 800px){
    .container {
        padding: 0 1rem;
    }
    h1 {
        font-size: 3rem;
    }
}
@media(max-width: 500px){
    h1 {
        font-size: 2.5 rem;
    }
    h2 {
        font-size: 1.5rem;
    }
}
              
            
!

JS

              
                class TypeWriter {
        constructor(txtElement, words, wait = 3000) {
            this.txtElement = txtElement;
            this.words = words;
            this.txt = '';
            //index of the the current string being typedout
            this.wordIndex = 0;
            //this.wait must be a base 10 interger
            this.wait = parseInt(wait, 10);
            //method type()
            this.type();
            // Boolean if the word is currently deleting
            this.isDeleting = false;
        }

        
        type() {
            //current index of words
            const current = this.wordIndex % this.words.length;
            //get full text of current word
            const fullTxt = this.words[current];

            // check if deleting
            if (this.isDeleting){
            //remove character
            this.txt = fullTxt.substring(0, this.txt.length - 1);
            } else {
            //add a charaacter
            this.txt = fullTxt.substring(0, this.txt.length + 1);
        }            

        
    

            // insert txt into element
            this.txtElement.innerHTML = `<span class="txt">${this.txt}</span>`;

            //type speed for when it is typing, deleting and pausing after deletion

            let typeSpeed = 300;

            //select pencil icon for writting animation
            const typingElement = document.querySelector('.fas');

            if (this.isDeleting){
                typeSpeed /= 4;        
            }
     
            if(this.isDeleting){
                typingElement.className = "fas fa-pencil-alt erasing-animation";
            }else{
                typingElement.className = "fas fa-pencil-alt writing-animation";
            }

            // if word is complete
            if(!this.isDeleting && this.txt === fullTxt){
                // make pause at end
                typeSpeed = this.wait;
                //set delete to true
                this.isDeleting = true;
                //will stop the pencil animation after word completion
                typingElement.className = "fas fa-pencil-alt";


            } else if (this.isDeleting && this.txt === ''){
                this.isDeleting = false;
                //move to the next word in the HTML property
                this.wordIndex++;
                // pause time before the word start typing
                typeSpeed = 1000;

            }

            setTimeout(() => this.type(), typeSpeed)
        }
    }


//Init On DOM Load
document.addEventListener('DOMContentLoaded', init);

//Init App
function init() {
    const txtElement = document.querySelector('.txt-type');
    // const words = JSON.parse(txtElement.getAttribute('data-words'));
  const words = ['Website?','Web App', 'Problem Solver?'];
  
  
    // const wait = txtElement.getAttribute('data-wait');
  const wait = 2500;
    
    new TypeWriter(txtElement, words, wait);
}
              
            
!
999px

Console