Last active
August 3, 2018 05:58
Revisions
-
funnythingz revised this gist
Aug 3, 2018 . 1 changed file with 10 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,7 @@ var elList = document.querySelectorAll('.el'); // 全部とじる function allClose() { for(var i, l = elList.length; i < l; i++) { (function(_el) { _el.classList.remove('open'); @@ -22,9 +21,14 @@ function accordion() { 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(); -
funnythingz created this gist
Aug 3, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ var el = document.querySelectorAll('.el')[0]; // 全部とじる function allClose() { var elList = document.querySelectorAll('.el'); 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: 対象のものだけ開く targetOpen(el); } // TODO: elをクリックすると全部とじてクリックしたものだけ開く el.addEventListener('click', accordion, false);