我有两个手风琴,一个放在另一个里面:主要的一个是类别,第二个是问题/答案对。
我的问题是,当我单击一个问题时,类别的整体 maxHeight 与以前相同,迫使我的问答对溢出,而不是添加到类别的 maxHeight。我对 Js 很陌生,所以我很难理解我所缺少的东西。我所有摆弄 js 代码的尝试都失败了。
这是我正在处理的代码笔:https://codepen.io/iuliard/pen/KKMzMLe
////ACCORDION////
var accordions1 = document.getElementsByClassName("category_name");
for (var i = 0; i < accordions1.length; i++) {
accordions1[i].onclick = function() {
this.classList.toggle('is-open');
var content1 = this.nextElementSibling;
if (content1.style.maxHeight) {
// accordion is currently open, so close it
content1.style.maxHeight = null;
} else {
// accordion is currently closed, so open it
content1.style.maxHeight = content1.scrollHeight + "px";
}
}
}
var accordions2 = document.getElementsByClassName("question");
for (var i = 0; i < accordions2.length; i++) {
accordions2[i].onclick = function() {
this.classList.toggle('is-open');
var content2 = this.nextElementSibling;
if (content2.style.maxHeight) {
// accordion is currently open, so close it
content2.style.maxHeight = null;
} else {
// accordion is currently closed, so open it
content2.style.maxHeight = content2.scrollHeight + "px";
}
}
}
慕斯709654
相关分类