Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var allDivs = document.getElementsByTagName('div');
- var c = 0;
- function next() {
- c = c + 1;
- c = c % allDivs.length;
- return allDivs[c];
- }
- function prev() {
- if (c === 0) {
- c = allDivs.length;
- }
- c = c - 1;
- return allDivs[c];
- }
- function checkKey(e) {
- e = e || window.event;
- // J
- if (e.keyCode == 74) {
- var current = allDivs[c];
- current.classList.remove('active');
- var p = prev();
- p.classList.add('active');
- }
- else if (e.keyCode == 75) {
- var current = allDivs[c];
- current.classList.remove('active');
- var n = next();
- n.classList.add('active');
- }
- else if (e.keyCode == 67) {
- for (var i = 0; i < allDivs.length; i++) {
- allDivs[i].classList.remove('active');
- }
- }
- }
- document.onkeydown = checkKey;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement