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 panell = this.nextElementSibling; | ||
+ | if (panell.style.maxHeight) { | ||
+ | panell.style.maxHeight = null; | ||
+ | } else { | ||
+ | panell.style.maxHeight = (panell.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 23:38, 30 September 2018