Last active
August 3, 2018 05:58
-
-
Save funnythingz/04a138c2f0087730d6c28fb831030a28 to your computer and use it in GitHub Desktop.
てきとうなので動かない
This file contains hidden or 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
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