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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <link href="https://fonts.googleapis.com/css?family=Ultra" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Kalam" rel="stylesheet" type="text/css"> 
<link href=" https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
<body>
  <h1> Quote Machine - Random Quotes with API</h1>
  </br>
<div id="mainarea">
  <div id="quotearea">
    <p></p>
  </div>
  <div id="authorarea">
    <p></p>
  </div>
  <div>
    <h2><button id="buttonchange" type="button" class="button button2">New Quote</button>
    <a id="tweetquote" target="_blank" title="Tweet the code!" class="button button2"><i class="fa fa-twitter fa-1x"></i></a>
    </h2>
    </div>
</div>

<h6 class="textcenter">Made by
                <a href="https://www.ionvarsescu.tk" target="_blank">Ion V.</a>
            </h6>
</body>
              
            
!

CSS

              
                h1 {
  font-family: Ultra, Monospace;
  font-size: 40px;
  text-align:center;
  padding-top:5px;
  }
h2 {
  text-align:center;
  padding-bottom:20px;
}

.textcenter {
  text-align:center;
  margin-top:50px;
}
#mainarea{
  position:relative;
  border-radius:10px;
  background-color:#99ffbb;
  width:50%;
  margin:auto;
  padding:20px;
}
#quotearea {
  font-family: Kalam, Cursive;
  font-size: 1.5em;
  text-align:center;
  padding:5px 5px;
  clear:both;
 }
#authorarea {
  font-family: Kalam, Cursive;
  font-size: 1.2em;
  text-align:right;
  padding:5px 5px;
  clear:both;
 }
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 15px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
    -webkit-transition-duration: 0.4s; /* Safari */
    transition-duration: 0.4s;
}


.button2:hover {
    box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 16px 0 rgba(0,0,0,0.19);
}
body {
  -webkit-transition: background-color 2s;
  transition: background-color 2s;
}
              
            
!

JS

              
                var quote="";
var author="";
var i=0;
var tweetcode="";
var color=["AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue","DarkCyan","DarkGoldenRod","DarkGray","DarkGrey","DarkGreen","DarkKhaki","DarkMagenta","DarkOliveGreen","Darkorange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray","DarkSlateGrey","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGray","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","GoldenRod","Gray","Grey","Green","GreenYellow","HoneyDew","HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush","LawnGreen","LemonChiffon","LightBlue","LightCoral","LightCyan","LightGoldenRodYellow","LightGray","LightGrey","LightGreen","LightPink","LightSalmon","LightSeaGreen","LightSkyBlue","LightSlateGray","LightSlateGrey","LightSteelBlue","LightYellow","Lime","LimeGreen","Linen","Magenta","Maroon","MediumAquaMarine","MediumBlue","MediumOrchid","MediumPurple","MediumSeaGreen","MediumSlateBlue","MediumSpringGreen","MediumTurquoise","MediumVioletRed","MidnightBlue","MintCream","MistyRose","Moccasin","NavajoWhite","Navy","OldLace","Olive","OliveDrab","Orange","OrangeRed","Orchid","PaleGoldenRod","PaleGreen","PaleTurquoise","PaleVioletRed","PapayaWhip","PeachPuff","Peru","Pink","Plum","PowderBlue","Purple","Red","RosyBrown","RoyalBlue","SaddleBrown","Salmon","SandyBrown","SeaGreen","SeaShell","Sienna","Silver","SkyBlue","SlateBlue","SlateGray","SlateGrey","Snow","SpringGreen","SteelBlue","Tan","Teal","Thistle","Tomato","Turquoise","Violet","Wheat","White","WhiteSmoke","Yellow","YellowGreen"];
$(document).ready(function() {
    $.getJSON('https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?', function(data) {
      quote = data.quoteText;
      author = data.quoteAuthor;
      tweetcode=quote+author;
          }).done(onupload);
  function onupload(){  document.getElementById("quotearea").innerHTML="<i class='fa fa-quote-left'></i>"+ quote+"<i class='fa fa-quote-right'></i>";
document.getElementById("authorarea").innerHTML=author;
                      if (tweetcode.length>126){
  tweetcode="Quote Machine with API - https://codepen.io/Nei_V/pen/kkRkvL"
}//with the hashtag the length is 140
$('#tweetquote').attr('href', 'https://twitter.com/intent/tweet?hashtags=QuoteMachine&related=javascript&text=' + encodeURIComponent(tweetcode));
                        };
  });

$(document).ready(function() {      $("#buttonchange").on("click",function(){
  $.getJSON('https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?', function(data) {
      quote = data.quoteText;
      author = data.quoteAuthor;
      tweetcode=quote+author;
          }).done(onupload).then(colors);
  function onupload(){  document.getElementById("quotearea").innerHTML="<i class='fa fa-quote-left'></i>"+ quote+"<i class='fa fa-quote-right'></i>";
document.getElementById("authorarea").innerHTML=author;
                       if (tweetcode.length>126){
  tweetcode="Quote Machine with API - https://codepen.io/Nei_V/pen/kkRkvL"
}//with the hashtag the length is 140
$('#tweetquote').attr('href', 'https://twitter.com/intent/tweet?hashtags=QuoteMachine&related=javascript&text=' + encodeURIComponent(tweetcode));
                        };
  function colors(){
  i=Math.floor((Math.random() * color.length) + 1);
    $("#quotearea").css("color",color[i]).toggle("fold",{horizFirst:true},2000).toggle("fold",{horizFirst:true},2000);
    $("#authorarea").css("color",color[i]);
    $("body").css("background-color",color[i-1]);//not an error - if i-1=0 then the background is white. Also, the color of the body is allways different then the collor of the texts-unlike in example.
  }
  
  });
                             });

/*
That's because the data is asynchronous. It doesn't come instantly. The ajax request will ask for the data, and the api server will process the request, gather the data and then send it back based on server load, speed, call stack, ect. Because of this, you can't place ajax data into the DOM until it's received. That's why ajax requests provide a 'callback', to output the data once it's been delivered.
You can chain multiple functions using jQuery's callback options

$.getJSON('https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?', function(data) {
    quote = data.quoteText;
    author = data.quoteAuthor;
    tweetcode = quote + author;
  }).done(showQuote).then(somethingElse);

  function showQuote() {
    document.getElementById("quotearea").innerHTML = quote;
    document.getElementById("authorarea").innerHTML = author;
  }

  function somethingElse() {
    console.log(quote, author);
  }
*/


              
            
!
999px

Console