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="wrapper">
<div class="container">  
<div class="header"><h1>Random Quote Generator</h1></div>
<div id="quote-box">
  <div class="quotecontainer">
  <div id="text">
    <p id="quotetext"></p>
  </div>
  <div id="author">
    <p id="quoteauthor"></p>
  </div>
  </div>
  <div class="buttons">
    <a class="button" id="tweet-quote" title="Tweet this quote!" target="_blank">
      <i class="fa fa-twitter"></i>
    </a>
    <button class="button" id="new-quote">New quote</button>
  </div>
</div>
  </div>
</div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Quicksand');
body {
  background-color: #000000;
  position: relative;
}
html,body{
  height:100%;
}
#wrapper {
  width: 100%;
  height: 100%;
  position: relative;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  background-repeat: no-repeat;
  background-size: cover;
}

.header {
  text-align: center;
  color: #ffffff;
  font-family: 'Quicksand', sans-serif;
}
#quote-box {
  margin: auto;
  position: relative;
  width: 500px;
  padding: 30px;
  background-color: white;
  border-radius: 5px;
  
  .quotecontainer {
    border-left: 3px solid #000000;
    padding-left: 8px;
    margin-bottom: 45px;
  }
}

#quotetext, #quoteauthor, #new-quote {
  font-family: 'Quicksand', sans-serif;
}
.buttons {
  display:flex;
  justify-content: space-between;
  margin: auto;
  width: 500px;
  
  .button {
    height: 38px;
    border-radius: 3px;
    border: none;
    color:#fff;
    background-color:#333;
    outline:none;
    font-size:0.85em;
    padding: 0 10px;
    opacity:1;
    cursor:pointer;
    &:hover {
      opacity: 0.8;
    }
    &#tweet-quote {
      padding:0px;
      padding-top:8px;
      text-align:center;
      font-size:1.2em;
      margin-right:5px;
      height:30px;
      width:40px;
    }
  }
}



              
            
!

JS

              
                $(document).ready(function() {
  
  function getQuote() {
    //call the array from a json file I've created
  $.getJSON('https://my-json-server.typicode.com/kikidesignnet/random_quote_generator/db', function(data) {
    //find out how many quotes there are
     var sourcelength = data.quoteSource.length;
    
    //get the random number
    var randomNumber = Math.floor(Math.random() * sourcelength);
    
    //get the quote and author from the array according to which position the random number get
      var quoteText = data.quoteSource[randomNumber].quote;
      var quoteAuthor = data.quoteSource[randomNumber].author;
     
     var speed = 500;
     
     $(".quotecontainer").animate({opacity: 0}, speed, function() {
       
       $(".quotecontainer").animate({opacity: 1}, speed);
       //attach the quote to empty #quotetext box
       $("#quotetext").text(quoteText);
     $("#quoteauthor").text("- " + quoteAuthor);
       
     });
     
   });
  };
  
  function getImage() {
  var backImages = ['https://res.cloudinary.com/kikibres/image/upload/v1543261939/FFC%20Random%20Quotes%20Images/quoteimg1.jpg', 'https://res.cloudinary.com/kikibres/image/upload/v1543261944/FFC%20Random%20Quotes%20Images/quoteimg2.jpg', 'https://res.cloudinary.com/kikibres/image/upload/v1543261944/FFC%20Random%20Quotes%20Images/quoteimg3.jpg', 'https://res.cloudinary.com/kikibres/image/upload/v1543261943/FFC%20Random%20Quotes%20Images/quoteimg4.jpg', 'https://res.cloudinary.com/kikibres/image/upload/v1543261943/FFC%20Random%20Quotes%20Images/quoteimg5.jpg', 'https://res.cloudinary.com/kikibres/image/upload/v1543261944/FFC%20Random%20Quotes%20Images/quoteimg6.jpg', 'https://res.cloudinary.com/kikibres/image/upload/v1543261946/FFC%20Random%20Quotes%20Images/quoteimg7.jpg', 'https://res.cloudinary.com/kikibres/image/upload/v1543261946/FFC%20Random%20Quotes%20Images/quoteimg8.jpg', 'https://res.cloudinary.com/kikibres/image/upload/v1543261946/FFC%20Random%20Quotes%20Images/quoteimg9.jpg', 'https://res.cloudinary.com/kikibres/image/upload/v1543261948/FFC%20Random%20Quotes%20Images/quoteimg10.jpg'];
    
    var randomImg = Math.floor(Math.random() * backImages.length);
    
    var quoteImg = backImages[randomImg];
    
    var speedimg = 1000;
    
      $("#wrapper").animate({opacity: 0}, speedimg, function() {
       
       $("#wrapper").animate({opacity: 1}, speedimg);
       $("#wrapper").css(
    'background-image', 'url(' + quoteImg + ')');
       
     });
    
  };
  
  //load the quote
  $("#new-quote").text(getQuote);
  $("#new-quote").html(getImage);
  //getImage();
   
  //call the quote on every click by #new-quote button
  $("#new-quote").on("click", getQuote);
  $("#new-quote").on("click", getImage);
  
  //share quote on twitter
  $("#tweet-quote").on("click", function() {
    $("#tweet-quote").attr("href", "https://twitter.com/intent/tweet?text="+ encodeURIComponent($("#quotetext").text()) + " " + encodeURIComponent($("#quoteauthor").text()));
  });
      
});
              
            
!
999px

Console