Advertisement
dariuszrorat

Bootstrap KnockoutJS list of climbing Knots

Oct 24th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.95 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pl">
  3. <head>
  4.     <meta charset="utf-8">
  5.     <title>List of knots</title>
  6.     <meta name="viewport" content="width=device-width, initial-scale=1">
  7.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  8.  
  9.     <style>
  10.         img {width: 240px; height: auto;}
  11.         img.active {width: 400px; height: auto;}
  12.         .container {margin-bottom: 120px;}
  13.     </style>
  14. </head>
  15. <body>
  16.     <div class="container">
  17.         <div class="jumbotron">
  18.             <h1>Knots</h1>
  19.             <p>Bootstrap and KnockoutJS based list of knots with image enlarge on hover.</p>
  20.        </div>
  21.         <table class="table table-condensed">
  22.             <thead>
  23.                 <tr>
  24.                     <th>Image</th>
  25.                     <th>Name</th>
  26.                     <th>Link</th>
  27.                 </tr>
  28.             </thead>
  29.             <tbody data-bind="foreach: items">
  30.                 <tr>
  31.                     <td><img data-bind="attr: {src: image}, hover: isHovering, css: {active: isHovering}"></td>
  32.                     <td data-bind="text: name"></td>
  33.                     <td><a data-bind="text: url,  attr: {href: url}"></a></td>
  34.                 </tr>
  35.             </tbody>
  36.         </table>
  37.     </div>
  38.  
  39.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  40.     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  41.     <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
  42.  
  43.     <script>
  44.         ko.bindingHandlers.hover = {
  45.             init: function (element, valueAccessor) {
  46.                 var value = valueAccessor();
  47.                 ko.applyBindingsToNode(element, {
  48.                     event: {
  49.                         mouseenter: function () { value(true) },
  50.                         mouseleave: function () { value(false) }
  51.                     }
  52.                 });
  53.             }
  54.         }
  55.  
  56.         var items = [
  57.             {
  58.                 'image': 'https://upload.wikimedia.org/wikipedia/commons/e/e6/Palstek_innen.jpg',
  59.                 'name': 'Bowline',
  60.                 'url': 'https://en.wikipedia.org/wiki/Bowline',
  61.                 'isHovering': ko.observable(false)
  62.             },
  63.             {
  64.                 'image': 'https://upload.wikimedia.org/wikipedia/commons/3/30/Alpine_butterfly_loop.jpg',
  65.                 'name': 'Alpine Butterfly',
  66.                 'url': 'https://en.wikipedia.org/wiki/Butterfly_loop',
  67.                 'isHovering': ko.observable(false)
  68.             },
  69.             {
  70.                 'image': 'https://upload.wikimedia.org/wikipedia/commons/3/39/Webeleinenstek.jpg',
  71.                 'name': 'Clove Hitch',
  72.                 'url': 'https://en.wikipedia.org/wiki/Clove_hitch',
  73.                 'isHovering': ko.observable(false)
  74.             }
  75.         ];
  76.  
  77.         ko.applyBindings(items);
  78.  
  79.     </script>
  80. </body>
  81. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement