cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="container-fluid">
  <h1>Quotes on Design</h1>
  <div id="buttonContainer">
    &nbsp;&nbsp;<a href="#" id="quoteButton">Quote Me</a>
  </div>
  <!--end buttonContainer-->
  <div id="outerQuoteContainer"><img class="quotelogo" src="http://www.xmaptools.com/wp-content/uploads/2011/10/QuotationMark.png" onerror="this.src=&quot;http://icons.iconarchive.com/icons/chrisbanks2/cold-fusion-hd/128/quotes-icon.png&quot;" height="40" width="40">


    <!-- Twitter Button -->
    <a id="tweet" href="https://twitter.com/share" class="twitter-share-button" {count} data-text="Read this Quote on Design!" data-size="default" data-via="Bee5pace" data-related="chriscoyier,twitterapi" data-hashtags="design,quotes" data-dnt="true" target="_blank"></a>


    <div id="quoteContainer" class="lead">
      <blockquote>
        <span id="quote" class="show">Quotation, n: The act of repeating erroneously the words of another.</span>
        <footer><span id="speaker" class="show">Ambrose Bierce</span></footer>
      </blockquote>
    </div>
    <!--end quoteContainer-->
  </div>
  <!--end outerQuoteContainer-->

  <div>
    <!-- citation and link -->
    <span class="text-info small">
      <cite>
        <span id="cite" class="show"><!-- append data -->
          &nbsp;&nbsp;Source:&nbsp;<a href="http://www.thedevilsdictionary.com/" target="blank">The Unabridged Devil's Dictionary</a></span>
    </cite>
    <span class="small text-left">
        <cite>
          <span id="linky" class="show"></span>
    <!-- append data -->
    </cite>
    </span>
  </div>
  <!-- citation and link -->

  

</div>
<!-- end container-fluid -->
            
          
!
            
              body {
  font-family: 'Merriweather', sans-serif;
  color: darkblue;
  max-width: 1110px;
  min-width: 305px;
}

blockquote {
  vertical-align: center;
  margin-right: .25em;
}

blockquote footer {
  color: inherit;
}

blockquote footer:before {
  content: url(http://www.xmaptools.com/wp-content/uploads/2011/10/QuotationMark.png);
}

.hidden {
  display: none;
}

.text-info {
  color: inherit;
  display: inline-block;
}

#outerQuoteContainer {
  width: 100%;
  min-width: 240px;
  background: -webkit-linear-gradient(right, darkblue, goldenrod);
  /*Safari 5.1-6*/
  
  background: -o-linear-gradient(right, darkblue, goldenrod);
  /*Opera 11.1-12*/
  
  background: -moz-linear-gradient(right, darkblue, goldenrod);
  /*Fx 3.6-15*/
  
  background: linear-gradient(to right, darkblue, goldenrod);
  /*Standard*/
  
  border: 4px solid goldenrod;
  padding: .1em .1em .1em 5em;
}

a#tweet {
  color: darkblue !important;
}

a#tweet:active,
a#tweet:hover {
  color: white !important;
  font-size: 90%;
}

.quotelogo {
  float: left;
  margin-left: -55px;
  margin-top: 15px;
  text-align: center;
}

.twitter-share-button {
  float: left;
  margin-left: -66px;
  margin-top: 65px;
}

.twitterlink {
  font-size: 80%;
}

#quoteContainer {
  width: 100%;
  background: -webkit-linear-gradient(left, white, goldenrod);
  /*Safari 5.1-6*/
  
  background: -o-linear-gradient(left, white, goldenrod);
  /*Opera 11.1-12*/
  
  background: -moz-linear-gradient(left, white, goldenrod);
  /*Fx 3.6-15*/
  
  background: linear-gradient(to left, white, goldenrod);
  /*Standard*/
  
  border: 1px solid goldenrod;
  padding-top: 1em;
  padding-left: 1em;
  margin: auto;
  text-align: left;
}

#buttonContainer {
  width: 50%;
  margin-left: 1.75em;
  margin-bottom: 1.75em;
}

#quoteButton {
  width: 120px;
  margin-top: 10px;
  border: 2px solid goldenrod;
  background-color: darkblue;
  color: white;
  font-family: inherit;
  font-weight: bold;
  padding: 5px;
  text-decoration: none;
  text-align: center;
  display: inline-block;
  border-radius: 11px;
}

#quoteButton:hover {
  cursor: pointer;
  background: goldenrod;
  color: darkblue;
  border: 2px solid darkblue;
}

#quoteButton:active {
  cursor: pointer;
}
            
          
!
            
              var source = "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=40&callback="
$.getJSON(source, function(a) {
  //iterate JSON, write the HTML and use CSS to hide/show with display:none;
  //use a button to change CSS to hide/show one of the 40 spans
  //for v3 close over the array value and pass it to a function outside the callback. may need to use a "promise".
  // can i attach the ID to a URL which also has a callback? Quote ID from QOD is ?p=ID
  // keep in mind adding multiple JSON sources with potentially URL ID identifiers. Use vars!
  jQuery.each(a, function(i, val) {
    var sourceID = (a[i].ID); // save for later to tweet or share to my page with selected quote
    var speaker = (a[i].title);
    var quote = (a[i].content);
    var linky = (a[i].link);
    if (typeof a[i].custom_meta !== 'undefined' && typeof a[i].custom_meta.Source !== 'undefined') {
      var cite = (a[i].custom_meta.Source);
    } else {
      var cite = "";
    };
    //call writeToDom within the callback to access the JSONP data
    writeToDom(sourceID, speaker, quote, linky, cite, i);
    // writeToDom must live within the callback as well.
    function writeToDom(sourceID, speaker, quote, linky, cite, i) {
      //write new spans for data
      if (i == 'undefined') {
        return; //conditional for button function, is this ok?
        //error message and handling here
      };
      var speakertag = "<span id=\"speaker" + i + "\" class=\"hidden\">" + speaker + "</span>";
      var quotetag = "<span id=\"quote" + i + "\" class=\"hidden\">" + quote + "</span>";
      var linkytag = "<span id=\"linky" + i + "\" class=\"hidden\">&nbsp;&nbsp;<a href=\"" + linky + "\">Link to Quote</a></span>";
      if (cite == "") {
        citetag = "<span id=\"cite" + i + "\" class=\"hidden\">" + cite + "</span>"
      } else {
        citetag = "<span id=\"cite" + i + "\" class=\"hidden\">&nbsp;&nbsp;Source:&nbsp;" + cite + "</span>"
      };
      $("#speaker").parent().append(speakertag);
      $("#quote").parent().prepend(quotetag);
      $("#linky").parent().append(linkytag);
      $("#cite").parent().prepend(citetag);
    }
  });

});
// if the source ID was appended to the *codepen* URL, get the quote by ID and *40* more quotes
$('#quoteButton').click(function(evt) {
  evt.preventDefault();
  var sourceLength = 40;
  var randomNumber = Math.floor(Math.random() * sourceLength);
  for (i = 0; i <= sourceLength; i += 1) {
    var timeAnimation = 600;
    var quoteContainer = $('#quoteContainer');
    var quoteID = "quote" + randomNumber;
    var speakerID = "speaker" + randomNumber;
    var linkyID = "linky" + randomNumber;
    var citeID = "cite" + randomNumber;
    //hide the current data
    quoteContainer.fadeOut(timeAnimation, function() {
      // check the IDs are passing
      //alert(quoteID + speakerID + linkyID + citeID);
      $(".show").addClass("hidden").removeClass("show");
      //while fadedout, show/hide the quote data with CSS with all spans
      //change class to hide in JS and CSS to align with bootstrap
      $("#" + quoteID).removeClass("hidden").addClass("show");
      $("#" + speakerID).removeClass("hidden").addClass("show");
      $("#" + linkyID).removeClass("hidden").addClass("show");
      $("#" + citeID).removeClass("hidden").addClass("show");
      quoteContainer.fadeIn(timeAnimation);
    });

    break;
  }; //end for loop
}); //end quoteButton function

// tweet button function
! function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0],
    p = /^http:/.test(d.location) ? 'http' : 'https';
  if (!d.getElementById(id)) {
    js = d.createElement(s);
    js.id = id;
    js.src = p + '://platform.twitter.com/widgets.js';
    fjs.parentNode.insertBefore(js, fjs);
  }
}(document, 'script', 'twitter-wjs');
            
          
!
999px
Loading ..................

Console