Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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="anth-posts" class="container" ></div>  
        <div id="loading">loading . . . 
        <img src="ripple.gif">            
        </div>       
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Montserrat');
body {
  font-family: 'montserrat', 'Helvetica Neue', Arial, Helvetica, sans-serif;
  background-color: lightgray;
}

a {
  text-decoration: none;
  color: #262626;
}

.container {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-flow: row wrap;
  justify-content: space-around;
  width: 80%;
  margin-right: auto;
  margin-left: auto;
}

.item {
  -webkit-flex: initial;
  flex: initial;
  width: 350px;
  height: 500px;
  border: 1px solid #e6e6e6;
  border-radius: 3px;
  margin-bottom: 20px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position-y: 55px;
  background-color: #fff;
  position: relative;
}

.info {
  padding: 8px 0 10px 0;
}

.author {
  color: #262626;
  font-weight: 600;
  font-size: 15px;
  line-height: 18px;
  display: inline-block;
  vertical-align: top;
  margin-left: 10px;
}

.date {
  display: inline-block;
  float: right;
  color: #999;
  margin-right: 12px;
  font-size: 12px;
  width: 60px;
}

.author-img {
  background-size: cover;
  background-repeat: no-repeat;
  overflow: hidden;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: inline-block;
  background-position: 2px;
  margin-left: 7px;
  background-color: #424242;
}

.anth-post-title {
  display: block;
  vertical-align: top;
  width: 80%;
  margin-left: 60px;
  margin-top: -20px;
  height: 20px;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.img-holder {
  height: 375px;
  width: auto;
  background-position: center;
}

.content {
  position: absolute;
  bottom: 0;
  margin: 10px;
  text-overflow: ellipsis;
  overflow: hidden;
  width: 95%;
  height: 70px;
}

#loading {
  width: 40%;
  margin: 20px auto;
  padding: 15px 20px;
}
              
            
!

JS

              
                
function checkPostsDiv(){
 
//see if we've got an anth-posts div before running all this stuff
  try {
  var element = document.getElementById('anth-posts');
  console.log(element);
    return element;
  }
  catch(err) {
      console.log(err.message);
  }
}

  if (checkPostsDiv()){ 

    var url = 'https://anth101.com/wp-json/wp/v2/posts?_embed&per_page=18&page=1';
    if (getRestrictions()){
      url = url + getRestrictions();
    }

    $(document).ready(function() {
      var def = new jQuery.Deferred();
      $.ajax({
        url: url,
        jsonp: "cb",
        dataType: 'json',
        success: function(data) {
            console.log(data); //dumps the data to the console to check if the callback is made successfully.
            $.each(data, function(index, item) {
              $('#anth-posts').append('<div class="item"><div class="info"><div class="author-img"><img src="' + item._embedded.author[0].avatar_urls[48] + '"></div><div class="author">'+item._embedded.author[0].name +'</div><div class="date">'+ dateDisplay(item) +'</div><a href="'+item.guid.rendered+'"><div class="anth-post-title">'+item.title.rendered+'</div></a><a href="'+item.guid.rendered+'"><div class="img-holder"' + backgroundImg(item)+'"></div></a><div class="content">'+item.excerpt.rendered+'</div><div class="anth-social">'+iLike(item)+'</div></div></div></div>');
            }); //each          
          } //success
      }); //ajax  
    }); //ready


//sets the background image based on the featured image or returns a default image
    function backgroundImg (item) {
      try {
       var imgUrl = item._embedded['wp:featuredmedia'][0].media_details.sizes.medium.source_url;
        return 'style="background-image:url('+imgUrl+');"';
      }
    catch(err) {
        return 'style="background-image:url(https://anth101.com/wp-content/plugins/js_composer/assets/vc/vc_gitem_image.png);';
      }
    }

//chops up the date item a bit
    function dateDisplay(item){
      return item.date.substring(5,10);
    }

    $(function(){

    //map two elements to scroll http://stackoverflow.com/a/16615769/3390935
     var $d = $($.map([$(window), $('#anth-posts')], function(el){return $.makeArray(el)})); //lets you read mouse position off two elements more easily

     var counter = 0;

      $d.on('scroll',function() {
        var scroll = getCurrentScroll();
        var pageHeight = $(document).height()-300;
        console.log(pageHeight);
        console.log(scroll);

          if ( $(window).scrollTop() + $(window).height() > pageHeight) {
               ++counter
               console.log('counter-'+counter);
               loadMore(counter, (24+ (counter*3)));
               console.log('foo!')
            }         
      });



     //scroll postion for triggering auto-load 
    function getCurrentScroll() {
        return window.pageYOffset || document.documentElement.scrollTop;
        }
    });

    function getDocHeight() {
        var D = document;
        return Math.max(
            D.body.scrollHeight, D.documentElement.scrollHeight,
            D.body.offsetHeight, D.documentElement.offsetHeight,
            D.body.clientHeight, D.documentElement.clientHeight
        );
    }

//load more on scroll position
    function loadMore (counter, offset){
      var url = 'https://anth101.com/wp-json/wp/v2/posts?_embed&per_page=3&offset='+offset;
     if (getRestrictions()){
       url = url + getRestrictions();
      }


      $(document).ready(function() {
        var def = new jQuery.Deferred();
        $.ajax({
          url: url,
          jsonp: "cb",
          dataType: 'json',
          success: function(data) {
              console.log(data); //dumps the data to the console to check if the callback is made successfully.
              $.each(data, function(index, item) {
              $('#anth-posts').append('<div class="item"><div class="info"><div class="author-img"><img src="' + item._embedded.author[0].avatar_urls[48] + '"></div><div class="author">'+item._embedded.author[0].name +'</div><div class="date">'+ dateDisplay(item) +'</div><a href="'+item.guid.rendered+'"><div class="anth-post-title">'+item.title.rendered+'</div></a><a href="'+item.guid.rendered+'"><div class="img-holder"' + backgroundImg(item)+'"></div></a><div class="content">'+item.excerpt.rendered+'</div><div class="anth-social">'+iLike(item)+'</div></div></div>');
              }); //each          
            } //success
        }); //ajax  
      }); //ready

    }

    var $loading = $('#loading').hide();
      $(document)
        .ajaxStart(function () {
          $loading.show();
        })
        .ajaxStop(function () {
          $loading.hide();
        });

}


//build out the like button for the iLike plugin
function iLike(item){
      return '<a href="#" class="dot-irecommendthis" id="dot-irecommendthis-'+item.id+'" title="Recommend this"><span class="dot-irecommendthis-count">&nbsp;</span> <span class="dot-irecommendthis-suffix"></span></a>'
    }


//get the category restriction in data-cats if exists
function getRestrictions(){
    var element = document.getElementById('anth-posts'); 
    if(element.dataset.cats){
      var cats = element.dataset.cats;
      console.log('&categories='+cats);
      return '&categories='+cats;
    }
}  
              
            
!
999px

Console