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

              
                <div id="wrapper">
  <div id="quote-wrapper">
      <h1 id="quote"></h1>
      <h5 id="author"></h5>
  </div>
  <div id="actions">
    <button id="nextQuote">Next</button>
     <button id="tweetQuote">Tweet Quote</button>
  </div>
</div>

              
            
!

CSS

              
                html, body {
    width: 100vw;
    height: 100vh;
    padding: 0 0 0 0;
    margin: 0;
}

body {
    background: black;
    padding-bottom: 80px;
    font-size: 50%;
}

#wrapper {
    display: flex;
    justify-content: center;
    height: calc(100vh - 80px);
    overflow: auto;
}

#wrapper:after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: url("http://dhaval.info/images/quotes_bg.jpg");
    background-repeat: no-repeat;
    background-size: cover;
    opacity: 0.1;
    z-index: -1;
}

#quote-wrapper {
    width: 90%;
    text-align: center;
    padding: 10px 35px;
}

#actions {
    position: fixed;
    bottom: 18px;
    color: #888;
    text-align: center;
    padding-top: 15px;
    font-family: cursive;
}

.char-group {
    display: inline-block;
    padding-left: 0.3em;
}

h1 {
    font-size: 3em;
    font-family: 'Averia Serif Libre', cursive;
    color: white;
    text-align: left;
}

h5 {
    font-size: 1.6em;
    font-family: 'Averia Serif Libre', cursive;
    color: gold;
    font-style: italic;
    text-align: right;
}

h1 .char {
    animation-name: bigToActual;
    animation-duration: 1s;
    display: inline-block;
}

h5 .char {
    animation-name: rightToLeft;
    animation-duration: 1s;
    display: inline-block;
}

.char.space {
    width: 0.3em;
}

button {
    border: 0;
    background: rgba(255, 215, 0, 0.8);
    outline: none;
    font-size: 1.4em;
    font-family: 'Averia Serif Libre', cursive;
    border-radius: 8px;
    color: #333;
    padding: 15px 25px;
    cursor: pointer;
}

button[disabled], button[disabled]:hover {
    color: #333;
    cursor: default;
}

button:hover {
    border-color: white;
    color: white;
    transition: all .3s;
}

@webkit-keyframe bigToActual {
    from {
        opacity: 0;
        color: black;
        translate: scale(4);
    }
    to {
        opacity: 1;
        color: #888;
        transform: scale(1);
    }
}

@keyframes bigToActual {
    from {
        opacity: 0;
        color: black;
        transform: scale(4);
    }
    to {
        opacity: 1;
        color: #888;
        transform: scale(1);
    }
}

@webkit-keyframe rightToLeft {
    from {
        opacity: 0;
        color: black;
        transform: translate(400px, 0) scale(0);
    }
    to {
        opacity: 1;
        color: white;
        transform: translate(0, 0) scale(1);
    }
}

@keyframes rightToLeft {
    from {
        opacity: 0;
        color: black;
        transform: translate(400px, 0) scale(0);
    }
    to {
        opacity: 1;
        color: white;
        transform: translate(0, 0) scale(1);
    }
}

@media only screen and (min-width:400px) {
    body {
        font-size: 100%;
    }
    #wrapper {
        align-items: center;
        height: 100vh;
    }
    #quote-wrapper {
        width: 70%;
        text-align: center;
        border: 1px solid #333;
        border-radius: 10px;
        background: rgba(50, 50, 50, 0.8);
        padding: 10px 35px;
    }
}
              
            
!

JS

              
                //using ajax to get json
function getQuoteFromServer(){
  return $.ajax({
    url:"https://raw.githubusercontent.com/ptldhaval/quotes/master/quotes.json",
    type:"GET",
    dataType:"text",
    contentType: 'application/x-www-form-urlencoded; charset=utf-8',
    crossDomain: true
  });
}

//set quotes async method to save json in local storage
var setQuotes = new Promise(function(resolve, reject){
  if (window.localStorage) {
      getQuoteFromServer().then(function(data){
        window.localStorage.removeItem("Quotes");
        window.localStorage.setItem("Quotes", data);
        resolve(true);
      }, function(e){
        reject(e);
      });
    }else{
      getQuoteFromServer().then(function(data){
        resolve(data);
      }, function(e){
        reject(e);
      });
    }
});
// get quotes async method 
var getQuotes = new Promise(function(resolve, reject){
  setQuotes.then(function(res){
    var jObject = [];
      if(typeof(res) === "boolean"){
        try{
          jObject = JSON.parse(window.localStorage.getItem("Quotes"));
        }catch(e){
          localStorage.removeItem("Quotes");
          jObject = {"quote":"Getting ERROR. Report to ptldhaval21@gmail.com", "author":"Dhaval"};
        }
      }else{
        jObject = JSON.parse(res);
      }
    resolve(jObject);
  }, function(e){
    reject(e);
  });
});

//charactor spliter and retrun html
function splitWordChar(b){
  return b.split(" ").map(function(d){
    var na = [];
    d.split("").map(function(e){
      na.push(e);
    });
    if(na.length > 0)
      return na;
  });
}
//append charactors to the html element
//parameters: obj -> data modal, elem -> target element to append, speed -> animation speed. 
function appendHTML(quote, elem, speed){
  return new Promise(function(resolve, reject){
    var obj = splitWordChar(quote);
    for(var i = 0; i<obj.length; i++){
      $("#" + elem).append('<span class="char-group '+ elem +'-char-'+ i +'"></span>');
    }
    var wc = 0;
    var cc = 0;
    var si = setInterval(function(){
      if(wc >= obj.length){
        clearInterval(si);
         resolve();
      }else{
        if(obj[wc]){
          if(cc < obj[wc].length){
            $("."+ elem +"-char-" + wc).append("<span class='char'>"+ obj[wc][cc] +"</span>");
          }else{
            wc++;
            cc = -1;     
          }
          cc++;
        }
      }
    }, speed)
  });
}
// global variable to store quote and author
var quote,author;
//show next quote method
function nextQuote(data){
  $("#quote, #author").html("");
  $("#nextQuote").attr("disabled", "disabled");
     quote = '"' + data[Math.floor(Math.random() * (data.length + 1))].quote + '"';
      author = "~" + data[Math.floor(Math.random() * (data.length + 1))].author;
    appendHTML(quote, "quote", 50).then(function(){
      setTimeout(function(){
        appendHTML(author, "author", 50).then(function(){
          $("#nextQuote").removeAttr("disabled");
        });
      },2000);
    });
}

//once dome is ready, call get quotes method to show the quotes. 
$(document).ready(function(){
  getQuotes.then(function(data){
    //once and first time call to get the first rendom quotes
    nextQuote(data);
    //get next rendom quotes by clicking on next button. 
    $("#nextQuote").click(function(){
      nextQuote(data);
    });
    $("#tweetQuote").click(function(){
      var url ="https://twitter.com/intent/tweet?text=" + encodeURI(quote + "\n" + author) ;
      window.open(url, "_blank");
    });
  }, function(error){
    console.log(error);
  });
});

              
            
!
999px

Console