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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div id="headlines"></div>
              
            
!

CSS

              
                #headlines > div{
  background-color:blue;
  width:300px;
  color:white;
  text-align:center;
  text-transform:uppercase;
  font-family:Arial;
  padding:5px;
  border: 1px solid white;
  // position:absolute;
}

#headlines > div ~ div{
  // opacity:0;
}
              
            
!

JS

              
                var myString = [];
myString = ["Test", "","Rest","Best"]; //Empty string is on purpose. The code below detects the empty string and removes it.
var delay_values = []; //The code below will push different numerical values into this array, based on whether there is an empty string found in the above array. In other words, "Test" will remain for 4 seconds instead of 2 (default), because there was an empty string after it.
var current = 0; //Position of empty string in relation to item.

myString.forEach(function(key, item){
   //Automatically push 2 as first value
  if(myString[item] == "" && item !== 0){ //Any empty string other than first item
    current++; //Capture number of items to go back
    var prev = item-current; //Go back to the correct item
    delay_values.splice(prev,prev, (delay_values[prev] + 2));//Add value of +2 to that item
    delay_values.splice(prev+1,prev+1);//Delete previous value replaced
  }else{
    current=0; //How deep into the array
    if(item >= myString.length-1){
      //if last item in array, do not add delay to array
    }else{
      delay_values.push(2); //Add value of 2 to first item and any other item that is not empty
    }
  }
})

var headlines_tl = new TimelineMax({paused:true}); //I want to append to this timeline. The timeline is paused until all logic is complete and sequences have been added.
myString = myString.filter(Boolean); //Remove empty strings from array.

myString.forEach(function(key, item){
  
  var headlines = document.getElementById("headlines");
  headlines.innerHTML += "<div>"+key+"</div>";
  var div = $("#headlines").find("div")[item];
  
  if(item == 0){ //if the item is first in the array, then we will only fade it out.
    headlines_tl.append(TweenMax.to(div, .5, {alpha:0, delay:delay_values[item]}));
  }else{ //if the item is not first in the array, we will fade it in first, then fade it out.
    
    headlines_tl.append(TweenMax.to(div, .5, {alpha:1}));
    
    if(item === myString.length-1){ //if the item is last in the array, we won't fade it out. it will remain indefinitely.
    }else{
      headlines_tl.append(TweenMax.to(div, .5, {alpha:0, delay:delay_values[item]}));
    }
  }
});
headlines_tl.restart(); //start the timeline.

              
            
!
999px

Console