BambooPanda (Talk | contribs) |
BambooPanda (Talk | contribs) |
||
Line 61: | Line 61: | ||
</div> | </div> | ||
</body> | </body> | ||
− | + | ||
+ | |||
<script> | <script> | ||
− | + | /***************************************************JAVASCRIPT STARTS HERE**************************************************/ | |
− | + | var acc = document.getElementsByClassName("accordion"); | |
− | + | var close = document.getElementsByClassName("accordion-closer"); | |
− | + | var inf = document.getElementsByClassName("infographic"); | |
− | + | var i; | |
+ | |||
+ | |||
+ | for (i = 0; i < acc.length; i++) { | ||
+ | acc[i].addEventListener("click", function() { | ||
+ | /* Toggle between adding and removing the "active" class, | ||
+ | to highlight the button that controls the panel */ | ||
+ | this.classList.toggle("active"); | ||
+ | |||
+ | /* Toggle between hiding and showing the active panel */ | ||
+ | |||
+ | var panel = this.nextElementSibling; | ||
+ | if (panel.style.display === "block") { | ||
+ | panel.style.display = "none"; | ||
+ | } else { | ||
+ | panel.style.display = "block"; | ||
} | } | ||
− | + | if (panel.style.maxHeight) { | |
− | + | panel.style.maxHeight = null; | |
− | + | } else { | |
+ | panel.style.maxHeight = panel.scrollHeight + "px"; | ||
} | } | ||
− | + | }); | |
− | + | } | |
+ | for (i = 0; i < close.length; i++) { | ||
+ | close[i].addEventListener("click", function(acc) { | ||
+ | |||
+ | this.parentElement.previousElementSibling.classList.toggle("active"); | ||
+ | var panel = this.parentElement; | ||
+ | panel.style.display = "none"; | ||
+ | if (panel.style.maxHeight) { | ||
+ | panel.style.maxHeight = null; | ||
+ | } else { | ||
+ | panel.style.maxHeight = panel.scrollHeight + "px"; | ||
+ | } | ||
+ | }); | ||
} | } | ||
+ | //for (i = 0; i < inf.length; i++) { | ||
+ | inf[0].addEventListener("click", function() { | ||
+ | |||
+ | acc[0].classList.toggle("active"); | ||
+ | var panel = acc[0].nextElementSibling; | ||
+ | if (panel.style.display === "block") { | ||
+ | panel.style.display = "none"; | ||
+ | } else { | ||
+ | panel.style.display = "block"; | ||
+ | } | ||
+ | if (panel.style.maxHeight) { | ||
+ | panel.style.maxHeight = null; | ||
+ | } else { | ||
+ | panel.style.maxHeight = panel.scrollHeight + "px"; | ||
+ | } | ||
+ | acc[0].scrollIntoView(); | ||
+ | }); | ||
+ | |||
+ | inf[1].addEventListener("click", function() { | ||
+ | |||
+ | acc[1].classList.toggle("active"); | ||
+ | var panel = acc[1].nextElementSibling; | ||
+ | if (panel.style.display === "block") { | ||
+ | panel.style.display = "none"; | ||
+ | } else { | ||
+ | panel.style.display = "block"; | ||
+ | } | ||
+ | if (panel.style.maxHeight) { | ||
+ | panel.style.maxHeight = null; | ||
+ | } else { | ||
+ | panel.style.maxHeight = panel.scrollHeight + "px"; | ||
+ | } | ||
+ | acc[1].scrollIntoView(); | ||
+ | }); | ||
+ | |||
+ | inf[2].addEventListener("click", function() { | ||
+ | |||
+ | acc[2].classList.toggle("active"); | ||
+ | var panel = acc[2].nextElementSibling; | ||
+ | if (panel.style.display === "block") { | ||
+ | panel.style.display = "none"; | ||
+ | } else { | ||
+ | panel.style.display = "block"; | ||
+ | } | ||
+ | if (panel.style.maxHeight) { | ||
+ | panel.style.maxHeight = null; | ||
+ | } else { | ||
+ | panel.style.maxHeight = panel.scrollHeight + "px"; | ||
+ | } | ||
+ | acc[2].scrollIntoView(); | ||
+ | }); | ||
+ | |||
+ | inf[3].addEventListener("click", function() { | ||
+ | |||
+ | acc[3].classList.toggle("active"); | ||
+ | var panel = acc[3].nextElementSibling; | ||
+ | if (panel.style.display === "block") { | ||
+ | panel.style.display = "none"; | ||
+ | } else { | ||
+ | panel.style.display = "block"; | ||
+ | } | ||
+ | if (panel.style.maxHeight) { | ||
+ | panel.style.maxHeight = null; | ||
+ | } else { | ||
+ | panel.style.maxHeight = panel.scrollHeight + "px"; | ||
+ | } | ||
+ | acc[3].scrollIntoView(); | ||
+ | }); | ||
+ | |||
+ | inf[4].addEventListener("click", function() { | ||
+ | |||
+ | acc[4].classList.toggle("active"); | ||
+ | var panel = acc[4].nextElementSibling; | ||
+ | if (panel.style.display === "block") { | ||
+ | panel.style.display = "none"; | ||
+ | } else { | ||
+ | panel.style.display = "block"; | ||
+ | } | ||
+ | if (panel.style.maxHeight) { | ||
+ | panel.style.maxHeight = null; | ||
+ | } else { | ||
+ | panel.style.maxHeight = panel.scrollHeight + "px"; | ||
+ | } | ||
+ | acc[4].scrollIntoView(); | ||
+ | }); | ||
+ | |||
+ | inf[5].addEventListener("click", function() { | ||
+ | |||
+ | acc[5].classList.toggle("active"); | ||
+ | var panel = acc[5].nextElementSibling; | ||
+ | if (panel.style.display === "block") { | ||
+ | panel.style.display = "none"; | ||
+ | } else { | ||
+ | panel.style.display = "block"; | ||
+ | } | ||
+ | if (panel.style.maxHeight) { | ||
+ | panel.style.maxHeight = null; | ||
+ | } else { | ||
+ | panel.style.maxHeight = panel.scrollHeight + "px"; | ||
+ | } | ||
+ | acc[5].scrollIntoView(); | ||
+ | }); | ||
+ | //} | ||
+ | /***************************************************JAVASCRIPT ENDS HERE****************************************************/ | ||
</script> | </script> | ||
Revision as of 18:45, 17 October 2018
CONNECT WITH US