Created
June 13, 2017 23:54
-
-
Save BekoBou/68a814be4ed2a32cb1eb681a6632aecf to your computer and use it in GitHub Desktop.
#3 Начинаем программировать
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mainContainer = document.querySelector(`div.app section.main`); | |
const template = document.querySelector(`#templates`); | |
const screens = [ | |
template.content.querySelector(`.main--welcome`), | |
template.content.querySelector(`.main--level-genre`), | |
template.content.querySelector(`.main--level-artist`), | |
template.content.querySelectorAll(`.main--result`)[0], | |
template.content.querySelectorAll(`.main--result`)[1] | |
]; | |
let currentScreenIndex = 0; | |
const showScreen = (screenIndex) => { | |
while (mainContainer.firstChild) { | |
mainContainer.removeChild(mainContainer.firstChild); | |
} | |
mainContainer.appendChild(screens[screenIndex]); | |
}; | |
showScreen(currentScreenIndex); | |
document.addEventListener(`keydown`, (e) => { | |
const backArrow = 37; | |
const forwardArrow = 39; | |
if (e.altKey && e.keyCode === backArrow) { | |
if (currentScreenIndex > 0) { | |
showScreen(--currentScreenIndex); | |
} | |
} else if (e.altKey && e.keyCode === forwardArrow) { | |
if (currentScreenIndex < screens.length - 1) { | |
showScreen(++currentScreenIndex); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment