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. 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

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

              
                <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<script src="https://use.fontawesome.com/0c4fc7df16.js"></script>

<div class = "container-fluid">
  <div class = "quotebox ">
    <div class = "row">
      <div class = "col-md-3"></div>
      <div id = "quotetext" class = "col-md-6"></div>
      <div class = "col-md-3"></div>
    </div>
    <div class = "row">
      <div class = "col-md-3"></div>
      <div id = "author" class = "text-right col-md-5"></div>
      <div class = "col-md-4"></div>
    </div>
    <div class = "row">
    <div id = "buttons">
    <button type = "button" class = "btn btn-primary" id = "newquote">New Quote</button>
    <a href = "https://twitter.com/intent/tweet" class = "twitter"><button type = "button" class = "btn btn-primary" id = "tweet"><i class = "fa fa-twitter"></i> Tweet</button></a>
    </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                body{
  background-color: #297A4A;
}

.btn{
  background-color: #297A4A;
  border: none;
  width: 150px;
  height: 50px;
  margin-top: 30px;
  font-size: 14pt;
}

.btn:hover{
  opacity: 0.7;
}

.container-fluid{
  padding: 0px;
}

.quotebox{
  border-color: black;
  border-width: 6px;
  border-style: solid none solid none;
  margin: 23vw auto 0 auto;
  padding: 30px 0px;
  background-color: #FFFFFF;
  width: 100%;
  font-family: "Montserrat", sans-serif;
  font-size: 2em;
}

#buttons{
  margin: 0px auto;
}

#quotetext, #author{
  color: white;
  transition: color .3s;
}
              
            
!

JS

              
                //todo: make the author fade in after the quote
//get rid of blue border after clicking button. .btn:active or .btn:focus don't seem to work

$(document).ready(function(){
  backgroundColors();
  getQuote();
  $("#newquote").on("click", getQuote);
                  });

//Get quote from API, perform fadeLetters on text and author. Going to have to make a second fade function for author because of interval conflict.

function getQuote(){
  $.ajax({
    url:"https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1",
    success: function(json){
      var post = json[0].content;
      var author = json[0].title;
    fadeLetters("#quotetext", $(post).text());
    //$("#author").html("-" + json[0].title);
    fadeAuthor("#author","-" + json[0].title);
    $(".twitter").attr("href", "https://twitter.com/intent/tweet?text=" +$(post).text() + " -" + author);
    },
    cache: false
  });
};

//Declare the interval globally so fadeLetters can clear it before it reassigns it. Allows spamming the New Quote button.
var interval;
var authorInterval;

function fadeLetters(id, str){
  $(id).empty();
  var counter = 0;
  clearInterval(interval);
  for(var i = 0; i < str.length; i++){
    $(id).append("<span id = " + i + ">" + str[i] + "</span>");
  }
  interval = setInterval(function(){
      $("#" + counter).animate({color: "black"}, 1000);
      counter++;
      if (counter > str.length){clearInterval(interval);}
    }, 15);
}; 

function fadeAuthor(id, str){
  $(id).empty();
  var acounter = 0;
  clearInterval(authorInterval);
  for(var i = 0; i < str.length; i++){
    $(id).append("<span id = a" + i + ">" + str[i] + "</span>");
  }
  authorInterval = setInterval(function(){
      $("#a" + acounter).animate({color: "black"}, 1000);
      acounter++;
      if (acounter > str.length){clearInterval(authorInterval);}
    }, 15);
}; 

//set possible background colors. can be any length, function will rotate left to right then back to beginning.
var bgcolors = ["#AA4E39", "#AA7539", "#27576B", "#297A4A"]
var bgcounter = 0;
//loop through bgcolors array, transitioning background between each color
function backgroundColors(){
  var bginterval = setInterval(function(){
    $("body").animate({"background-color": bgcolors[bgcounter]}, 14000);
    $(".btn").animate({"background-color": bgcolors[bgcounter]}, 14000);
    bgcounter++;
    if (bgcounter > bgcolors.length){bgcounter = 0;}
  });
}
              
            
!
999px

Console