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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <p class='sorting-controls'>Sort by: <a href='#score'>Score</a> | <a href='#name'>Name</a></p>
<p class='current-sorting-by'>Currently sorting by <span>nothing</span>.</p>
<div id="player-board">
</div>


<!-- Not for displaying. For JS to use -->
<div class="template">
  <div class="player">
    <div class="profile-pic">
      <img src='' alt='profile pic placeholder'>      
    </div>
    <p class="name"></p>
    <p class="score"></p>
  </div>
</div>
              
            
!

CSS

              
                /* Hide the template */
.template {
  display: none;
}

/* Styles for the player score card */
.player {
  width: 50%;
  margin: 20px auto;  
  overflow: auto;
  border: 2px solid BROWN;
  border-radius: 5px;
  padding: 10px;
  background: FLORALWHITE;
}
.player .profile-pic {
  width: 33%;
  float: left;  
}
.player .name {
  float: left;  
  width: 66%;
  padding-left: 5px;  
/*   font-weight: 700; */
  font-size: 120%;
}
.player .score {
  float: left;
  width: 66%;
  padding-left: 5px;
  font-size: 48pt;
  font-weight: 700;  
  color: LIGHTGREY;
}

/* Not our focus */
* {
  box-sizing: border-box;
}
body {
  font-size: 16pt;
  padding: 50px;
}
img {
  max-width: 100%;
}
p {
  margin: 0;
}


              
            
!

JS

              
                // Data
var players = [
  {
    name: "Tom Chan",
    score: 68,
    pic: "http://placehold.it/150x150&text=FW"
  },
  {
    name: "Steven Ku",
    score: 73,
    pic: "http://placehold.it/150x150&text=KW"
  },
  {
    name: "Francis Wong",
    score: 82,
    pic: "http://placehold.it/150x150&text=TC"
  },
  {
    name: "Ken Wong",
    score: 98,
    pic: "http://placehold.it/150x150&text=SK"
  },
];

// construct the list from data
function createListFromData() {
  // empty the container
  $('#player-board').empty();
  
  // construct the list
	$.each(players, function(){
    var playerObj = this;
    var clone = $('.template').find('.player').clone();
    clone.find('.name').text( playerObj.name );
    clone.find('.score').text( playerObj.score );
    clone.find('.profile-pic img').prop( 'src', playerObj.pic );

    $('#player-board').append(clone);

  });  
}

// call the function once on start up
createListFromData();

// View links handling
$('.sorting-controls > a').click(function(){
  // determine which sorting
  var sortBy = $(this).attr('href').substring(1); // get 'score' or 'name'
	
  // tell the user that we are sorting.
  $('.current-sorting-by').find('span').text( sortBy );
  
  // sort the data
  players.sort(function(a, b){
    if (a[sortBy] <= b[sortBy]) {
      return -1;
    } else {
      return 1;
    }
  });
  
  createListFromData();
  
  return false;
});

              
            
!
999px

Console