Line 7: | Line 7: | ||
<script> | <script> | ||
− | + | var acc = document.getElementsByClassName("accordion"); | |
− | + | var i; | |
− | + | console.log(acc) | |
− | + | for (i = 0; i < acc.length ; i++) { | |
− | + | acc[i].addEventListener("click", function() { | |
− | + | this.classList.toggle("active"); | |
− | + | var panel = this.nextElementSibling; | |
− | + | if (panel.style.maxHeight) { | |
− | + | panel.style.maxHeight = null; | |
− | + | } else { | |
− | + | panel.style.maxHeight = (panel.scrollHeight + "px"); | |
− | + | } | |
− | + | }); | |
− | + | } | |
− | + | ||
− | + | ||
+ | |||
+ | function openAll(expt) { | ||
+ | console.log("click active") | ||
+ | var i, panelList; | ||
+ | panelList = document.getElementsByClassName(expt); | ||
+ | console.log(panelList) | ||
+ | |||
− | + | for (i = 2; i < panelList.length; i++) { | |
− | + | if (panelList[i].style.maxHeight == 0) { | |
− | + | console.log(panelList[i].style.maxHeight) | |
− | + | panelList[i].style.maxHeight = panelList[i].scrollHeight + "px" | |
− | + | console.log("open") | |
− | + | panelList[0].style.color = "#F76C6C"; | |
− | + | panelList[1].style.color = "#F76C6C"; | |
− | + | panelList[1].style.transform = "rotate(180deg)" | |
− | + | ||
− | + | } else { | |
− | + | console.log(panelList[i].style.maxHeight) | |
− | + | panelList[i].style.maxHeight = null ; | |
− | + | console.log("close"); | |
− | + | panelList[0].style.color = "#374785"; | |
− | + | panelList[1].style.color = "#374785"; | |
+ | panelList[1].style.transform = "rotate(0deg)"; | ||
+ | } | ||
+ | } | ||
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</script> | </script> |
Revision as of 20:18, 1 October 2018