<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<ul>
<li><button>1</button></li>
<li><button>2</button></li>
<li><button>3</button></li>
<li><button>4</button></li>
<li><button>5</button></li>
<li><button>6</button></li>
<li><button>7</button></li>
<li><button>8</button></li>
<li><button>9</button></li>
<li><button>10</button></li>
<li><button>11</button></li>
<li><button>12</button></li>
<li><button>13</button></li>
<li><button>14</button></li>
<li><button>15</button></li>
<li><button>16</button></li>
<li><button>17</button></li>
<li><button>18</button></li>
<li><button>19</button></li>
<li><button>20</button></li>
</ul>
</body>
</html>
/*
Gridnav - a way to navigate lists with a keyboard in a
2D fashion instea of item-by-item
Copyright (c) 2016 Christian Heilmann
Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php
Version: 1.0.0
*/
var Gridnav = function (listelement) {
var that = this;
this.list = document.querySelector(listelement);
if (!this.list) {
throw Error('List item could not be found');
}
this.setcodes = function (amount) {
that.codes = {
39:1, 68:1,
65:-1, 37:-1,
87:-that.amount, 38:-that.amount,
83: that.amount, 40:that.amount
};
}
this.getamount = function () {
that.amount = Math.floor(
that.list.offsetWidth / that.list.firstElementChild.offsetWidth
);
that.setcodes(that.amount);
}
if (!this.list.getAttribute('data-element')) {
this.element = this.list.firstElementChild.firstElementChild.tagName;
} else {
this.element = this.list.getAttribute('data-element').toUpperCase();
}
if (!this.list.getAttribute('data-amount')) {
this.getamount();
window.addEventListener('resize', that.getamount);
} else {
this.amount = +this.list.getAttribute('data-amount');
}
this.setcodes(this.amount);
this.all = this.list.querySelectorAll(this.element);
this.keynav = function(ev) {
var t = ev.target;
if (t.tagName === that.element) {
for (var i = 0; i < that.all.length; i++) {
if (that.all[i] === t) {
c = i;
break;
}
}
if (that.codes[ev.keyCode]) {
if (that.all[c + that.codes[ev.keyCode]]) {
that.all[c + that.codes[ev.keyCode]].focus();
}
}
}
}
this.list.addEventListener('keyup', this.keynav);
};
var makeitso = new Gridnav('ul');
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |