Skip to content

Instantly share code, notes, and snippets.

@funnythingz
Last active August 3, 2018 05:58
Show Gist options
  • Save funnythingz/04a138c2f0087730d6c28fb831030a28 to your computer and use it in GitHub Desktop.
Save funnythingz/04a138c2f0087730d6c28fb831030a28 to your computer and use it in GitHub Desktop.
てきとうなので動かない
var elList = document.querySelectorAll('.el');
// 全部とじる
function allClose() {
for(var i, l = elList.length; i < l; i++) {
(function(_el) {
_el.classList.remove('open');
_el.classList.add('close');
})(elList[i]);
}
}
// ひらく
function targetOpen(el) {
el.classList.remove('close');
el.classList.add('open');
}
function accordion() {
// TODO: まず全部閉じる
allClose();
// TOOD: 対象のものだけ開く
for(var i, l = elList.length; i < l; i++) {
(function(_el) {
// TODO: elをクリックすると全部とじてクリックしたものだけ開く
_el.addEventListener('click', function() {
targetOpen(_el);
}, false);
})(elList[i]);
}
}
accordion();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment