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

              
                <body >
    <div class="bg">
      <h1>Cafe so and so</h1>
      <h2>There's something for<span id="message"> everyone.</span><span class="cursor">|</span></h2>
    </div>
</body>
              
            
!

CSS

              
                
body {
  background: #ccc;
  padding: 1em;
}

.bg {
  background-image: url(https://via.placeholder.com/200x100);
}

div {
  height:500px;
}

/* BLINKING CURSOR */
.cursor {
  font-weight: 100;
  font-size: 30px;
  color: #2E3D48;
  -webkit-animation: 1s blink step-end infinite;
  -moz-animation: 1s blink step-end infinite;
  -ms-animation: 1s blink step-end infinite;
  -o-animation: 1s blink step-end infinite;
  animation: 1s blink step-end infinite;
}

@keyframes "blink" {
  from, to {
    color: transparent;
  }
  50% {
    color: black;
  }
}

@-moz-keyframes blink {
  from, to {
    color: transparent;
  }
  50% {
    color: black;
  }
}

@-webkit-keyframes "blink" {
  from, to {
    color: transparent;
  }
  50% {
    color: black;
  }
}

@-ms-keyframes "blink" {
  from, to {
    color: transparent;
  }
  50% {
    color: black;
  }
}

@-o-keyframes "blink" {
  from, to {
    color: transparent;
  }
  50% {
    color: black;
  }
}
/* END BLINKING CURSOR */

              
            
!

JS

              
                let messages = [
  " everyone.",
  " dog owners.",
  " the diet-conscious.",
  " workers.",
  " families."
];

//These are images that correspond with the messages array in the same location, so they have to be in sync
let images = [
  "url(https://via.placeholder.com/200x100)",
  "url(https://via.placeholder.com/400x100)",
  "url(https://via.placeholder.com/400x200)",
  "url(https://via.placeholder.com/400x300)",
  "url(https://via.placeholder.com/400x400)"

];
 
let loopDuration = 3000;

let i = 0;

function displayMessages() {

      let write = document.getElementById("message").innerText.length === 0; // initialise the state
      let char = document.getElementById("message").innerText.length; // the number of characters of the message
      console.log('write = ' + write);
  
      function typeWriter() {
        document.getElementById("message").innerText += messages[i].charAt(char++);               
      }
      function backSpacer() {
        document.getElementById("message").innerText = messages[i].substr(0, --char);
      }
      function displayImages() {
        //$('.bg').fadeTo('slow', 0.3, function() { //fade out the previous image
        //  $(this).css("background-image",images[i]); //change the image
        //}).fadeTo('slow',1); //fade into the new image
        $('.bg').css("background-image",images[i])
      }
      
      function nextStep() {
        let time = 50;
        if (write === true) { //if there is no message
          typeWriter(); //type the message out

          if (char === messages[i].length) { //if the current length has reached the full length
            write = false; // Stop running write === true stuff
            time = loopDuration - char * time * 2 - 500; // Wait x ms before erasing; wait for full duration minus the time taken to write and backspace
          }
        } else if (write === false) { //Change the state and do something else
          backSpacer(); // Backspace it


          if (char === 0) { // Once it's all deleted - there's no characters
            write = null; //Change the state and do something else
          }
        }
        setTimeout(nextStep, time); //run through the function every $time ms
      }
      
      nextStep();
      displayImages(); //move to the next image 
}


function loop() {
  //setInterval(function() {
    //reset i to start the messages again
    if(++i >= messages.length) i = 0;
    //i = Math.floor(Math.random() * 6); //randomness produces same text twice in a row which looks unprofessioanal
    displayMessages(); 
  //},loopDuration);
}



//Run the function
window.onload = function loadChanges() { //wait to see if page has loaded
  setTimeout(function() {
    setTimeout(displayMessages, 1500); //run first to delete message
    setTimeout(function run() {
      loop();
      setTimeout(run, 3300);
    }, 3000);
    //loop(); 
  }, 1000) //wait a further x ms
};

              
            
!
999px

Console