Oba tyto globální proměnné práci v kódu.
Jak víte, který je ten pravý, pokud oba pracují v kódu?
Bylo mi řečeno, že jeden je ten pravý, ale jak víte, který z nich použít?
Pokud oba pracují v kódu?
Také jsem právě řekl, tyto absolutně není to samé pod kapotou. Zatímco kód může spustit a zobrazí se v obou JSFiddle verze, ve skutečnosti to není.
Může mi někdo pomoci pochopit, což je správně používat a proč?
let currentPlayButton = {};
https://jsfiddle.net/n5cpvtok/
let currentPlayButton = “”;
https://jsfiddle.net/n5cpvtok/1/
let currentPlayButton;
https://jsfiddle.net/bo5jm2r6/
Já nevidím rozdíl.
Když svg jsou klikli, se fade out.
Což je očekávané chování.
const manageCover = (function makeManageCover() {
const config = {};
const body = document.body;
let currentPlayButton = {};
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
function hideAll(elements) {
elements.forEach(hide);
}
function resetBackground(backgroundSelector) {
const allBackgrounds = document.querySelectorAll(backgroundSelector);
function hideBackground(background) {
background.classList.add("bg1");
}
allBackgrounds.forEach(hideBackground);
}
function resetButtons(buttonSelector) {
const allButtons = document.querySelectorAll(buttonSelector);
function hideButton(button) {
button.classList.add("isOpen");
}
allButtons.forEach(hideButton);
}
function resetPage() {
resetBackground("body");
resetButtons(".outer");
}
function markAsPlayed(played) {
played.classList.add("played");
}
function showCover(playButton) {
hideAll(config.containers);
resetPage();
markAsPlayed(playButton);
const cover = playButton.parentElement;
cover.classList.add("active");
show(cover);
}
function animationEndHandler(evt) {
const animationName = evt.animationName;
if (animationName === "initial-fade") {
body.classList.remove("initial-fade");
showCover(currentPlayButton);
}
}
function coverClickHandler(evt) {
currentPlayButton = evt.currentTarget;
body.classList.add("initial-fade");
}
function addClickToButtons(playButtons) {
playButtons.forEach(function playButtonHandler(playButton) {
playButton.addEventListener("click", coverClickHandler);
});
}
function addCoverHandler(coverSelector, handler) {
const cover = document.querySelector(coverSelector);
cover.addEventListener("click", handler);
}
function init(selectors) {
config.containers = document.querySelectorAll(selectors.container);
const playButtons = document.querySelectorAll(selectors.playButton);
addClickToButtons(playButtons);
body.addEventListener("animationend", animationEndHandler);
}
return {
addCoverHandler,
init
};
}());