Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://static.jsbin.com/js/vendor/traceur.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<meta charset=utf-8 />
<title>Test Page</title>
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  body {
    font-family: sans-serif;
  }
  p {
    margin: 0px;
  }
  #productList {
    margin: 0;
    padding: 2px;
    border: 1px solid #bbb;
    list-style-type: none;
  }
  #productList > li {
    margin: 2px;
    padding: 0px;
    border: 1px solid #bbb;
    background-color: #eee;
  }
  #productList > li > img {
    float: left;
  }
</style>
</head>
<body>
  <div>asdasd
    <button id='btnPrev'>&lt;&lt;&nbsp;Previous</button>
    <button id='btnNext'>Next&nbsp;&gt;&gt;</button>
  </div>
  <ul id='productList'>
  </ul>
  <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script?
</body>
</html>
 
jQuery(function($) {
  alert('hi');
  var startingProduct = -1;
  var pageSize = 2;
  var productCount = 6;
  
  // Initial product load
  loadProducts(0, pageSize);
  
  // Load previous set
  $('#btnPrev').click(function() {
    var start = Math.max(startingProduct - pageSize, 0);
    if (start !== startingProduct) {
      loadProducts(start, pageSize);
    }
  });
  // Load next set
  $('#btnNext').click(function() {
    alert('hi');
    var start = Math.min(startingProduct + pageSize, productCount);
    
    if (start !== startingProduct) {
      loadProducts(start, pageSize);
    }
  });
  
  function updateButtons() {
    $('#btnNext')[0].disabled = startingProduct + pageSize >= productCount;
    $('#btnPrev')[0].disabled = startingProduct === 0;
  }
  
  // Product loader
  function loadProducts(start, count) {
    // The implementation here is completely different than it would
    // be on a real size. Here we're just faking the Ajax
    var markup;
    
    switch (start) {
      case 0:
        break;
      default:
        startingProduct = 0;
        markup =
           buildProductMarkup("001", "88ca83ed97a129596d6e8dd86deef994") +
           buildProductMarkup("002", "ca3e484c121268e4c8302616b2395eb9");
        break;
      case 2:
        startingProduct = 2;
        markup =
           buildProductMarkup("003", "f1570fff80187e342e69951edc552bff") +
           buildProductMarkup("004", "f858a5d21c7c306f472ace32d3cc2fda");
        break;
      case 4:
        startingProduct = 4;
        markup =
           buildProductMarkup("005", "6d8ebb117e8d83d74ea95fbdd0f87e13") +
           buildProductMarkup("006", "b4ae7f8b50a2c32287e456394570679");
        break;
    }
    updateButtons();
    $('#productList').html(markup);
  }
  
  function buildProductMarkup(prodNum, gravatarId) {
    return [
        "<li id='product-" + prodNum + "'>",
          "<div>This is Product " + prodNum + "</div>",
          "<div><img style='width: 32px; height: 32px' src='http://www.gravatar.com/avatar/" + gravatarId + "?s=32&d=identicon&r=PG'>",
          "Blurb about Product " + prodNum + "</div>",
        "</li>"
      ].join("");
  }
});
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers