cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <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>
            
          
!
            
              
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 */

            
          
!
            
              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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console