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

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console