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="masthead">
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/387928/nyt-logo.png" height="80" id="nyt-logo">
</div>

<div id="reviews">
   <!-- reviews -->
</div>

<div id="best-seller-titles">
  <!-- best sellers -->
</div>


              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600)
@import url(https://fonts.googleapis.com/css?family=Rozha+One)

*
  box-sizing: border-box
  background-color: #fff
  font-family: 'Open Sans', sans-serif

.book-cover
  display: block
  margin: 0 auto
  width: 200px
  transform: translateY(-30px)
  
.entry
  margin: 30px 0px
  padding: 20px 50px
  -webkit-box-shadow: 2px 2px 2px 0px rgba(0,0,0,0.21)
  -moz-box-shadow: 2px 2px 2px 0px rgba(0,0,0,0.21)
  box-shadow: 0px 0px 8px 0px rgba(0,0,0,0.21)
  &:before
    content:  attr(nyt-rank)
    font-family: 'Rozha One', serif
    font-size: 3rem
    display: inline-block
    width: 50px
    height: 50px
    line-height: 50px
    padding: 20px 20px
    text-align: center
    transform: translate(-100px)
    border: 4px solid #282c37
    background-color: #fff
    border-radius: 50%
    color: #282c37
    -webkit-box-shadow: 0px 0px 8px 0px rgba(0,0,0,0.21)
    -moz-box-shadow: 0px 0px 8px 0px rgba(0,0,0,0.21)  
    box-shadow: 0px 0px 8px 0px rgba(0,0,0,0.21)
  
#best-seller-titles
  max-width: 475px
  margin: 120px auto
  & a
    margin: 40px 0px 0px 0px
    text-decoration: none
    color: #2b90d9
    line-height: .2
  & h1, h2, h3, h4
    color: #282c37
  & p 
    color: #333030
    line-height: 1.4
  .publisher
    color: #333030
  .stats
    hr
      opacity: .5
    & p
      color: #282c37
 
#masthead
  position: fixed
  top: 0
  left: 0
  background: #FFF
  z-index: 9999
  width: 100%
  padding: 10px
  -webkit-box-shadow: 0px 1px 5px 0px #777
  -moz-box-shadow: 0px 1px 5px 0px #777
  box-shadow: 0px 1px 5px 0px #777
  transition: 200ms
  img
    transition: 100ms
              
            
!

JS

              
                fetch('https://api.nytimes.com/svc/books/v3/lists.json?list-name=hardcover-fiction&api-key=6ad84e249d054efeaefe1abb8f89df5b', {
    method: 'get',
  })
  .then(response => { return response.json(); })
  .then(json => { updateBestSellers(json); })
  .catch(error => {
    console.log('NYT API Error: Defaulting to nytimes archival data.', error);
    updateBestSellers(nytimesArchive);
  });

function updateBestSellers(nytimesBestSellers) {
  nytimesBestSellers.results.forEach(function(book) {
    var isbn = book.isbns[0].isbn10;
    var bookInfo = book.book_details[0];
    var lastWeekRank = book.rank_last_week || 'n/a';
    var weeksOnList = book.weeks_on_list || 'New this week!';
    var listing = 
        '<div id="' + book.rank + '" class="entry">' + 
          '<p>' + 
          '<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/387928/book%20placeholder.png" class="book-cover" id="cover-' + book.rank + '">' + 
          '</p>' + 
          '<h2><a href="' + book.amazon_product_url + '" target="_blank">' + bookInfo.title + '</a></h2>' +
          '<h4>By ' + bookInfo.author + '</h4>' +
          '<h4 class="publisher">' + bookInfo.publisher + '</h4>' +
          '<p>' + bookInfo.description + '</p>' + 
          '<div class="stats">' +
            '<hr>' + 
            '<p>Last Week: ' + lastWeekRank + '</p>' + 
            '<p>Weeks on list: ' + weeksOnList + '</p>' +
          '</div>' +
        '</div>';

    $('#best-seller-titles').append(listing);
    $('#' + book.rank).attr('nyt-rank', book.rank);

    updateCover(book.rank, isbn);
  });
}

function updateCover(id, isbn) {
  fetch('https://www.googleapis.com/books/v1/volumes?q=isbn:' + isbn + "&key=AIzaSyAyINR2SYnt4K-0x6zh6S3x6NVUY15pY7Q", {
    method: 'get'
  })
  .then(response => { return response.json(); })
  .then(data => {
    var img = data.items[0].volumeInfo.imageLinks.thumbnail;
    img = img.replace(/^http:\/\//i, 'https://');
    $('#cover-' + id).attr('src', img);
  })
  .catch(error => {
    console.log(error);
    // console.log('Googel API Error: Defaulting to archival images for book #' + id + ' ISBN: ' + isbn);
    // var index = id - 1;
    // var img = archivedImages[index];
    // $('#cover-' + id).attr('src', img);
  });
}

$(window).scroll(function (event) {
    var scroll = $(window).scrollTop();
    if (scroll > 50) {
      $('#masthead').css({'height':'50', 'padding' : '8'})
      $('#nyt-logo').css({'height':'35'})
    } else {
      $('#masthead').css({'height':'100', 'padding':'10'});
      $('#nyt-logo').css({'height':'80'})
    }
});
              
            
!
999px

Console