第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何解決雙手風(fēng)琴中的 maxHeight?

如何解決雙手風(fēng)琴中的 maxHeight?

慕碼人8056858 2023-05-19 16:11:58
我有兩個手風(fēng)琴,一個放在另一個里面:主要的一個是類別,第二個是問題/答案對。我的問題是,當(dāng)我單擊一個問題時,類別的整體 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";    }  }}
查看完整描述

1 回答

?
慕斯709654

TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個贊

您必須計算每個打開max-height的。所以我修改了你打開問題的代碼。您可以在此問題的末尾查看基于您的代碼的工作示例。category_contentquestion

我做了什么

在設(shè)置問題內(nèi)容的高度之前:
content2.style.maxHeight = content2.scrollHeight + "px";
將父類別內(nèi)容放入變量中:
const parent = content2.closest(".category_content");
獲取其高度(我使用 parseInt() 獲取“305”而不是“305 px ”)并將其與問題內(nèi)容高度相加:
const parentHeight = parseInt(parent.style.maxHeight) + content2.scrollHeight;
之后應(yīng)用新高度(父母+孩子身高):
parent.style.maxHeight = parentHeight + "px"; 我們開始吧。

這只是向您指出正確解決方案的示例

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 {

      // ↓↓↓ this is what I've modified ↓↓↓

      const parent = content2.closest(".category_content");

      const parentHeight = parseInt(parent.style.maxHeight) + content2.scrollHeight;

      parent.style.maxHeight = parentHeight + "px";

      // accordion is currently closed, so open it

      content2.style.maxHeight = content2.scrollHeight + "px";

    }

  }

}

@import url("https://rsms.me/inter/inter.css");

html {

  font-family: "Inter", sans-serif;

}

@supports (font-variation-settings: normal) {

  html {

    font-family: "Inter var", sans-serif;

  }

}


body {

  background: orange;

}


/* ACCORDION  */

.container {

  max-width: 100%;

  padding: 0px 35px;

}


.category {

  padding-top: 25px;

}


/* category name */

dl h3 {

  font-family: "Inter";

  font-weight: 500;

  font-size: 18px;

  text-align: left;

  text-transform: uppercase;

  padding-bottom: 20px;

  border-bottom: 1px solid black;

  line-height: 1.7;

  cursor: pointer;

  transition: 0.2s linear;

}


dl h3:hover {

  transform: translateX(3px);

}


/* question */

dt h4 {

  display: flex;

  order: 2;

  max-width: 50%;

  font-size: 16px;

  font-weight: 400;

  line-height: 180%;

}


/* answer */

dd p {

  font-family: "Inter";

  font-size: 16px;

  max-width: 75ch;

  line-height: 180%;

  padding-left: 29px;

  padding-bottom: 20px;

  font-weight: 400;

}


a {

  color: black;

}


.category_content {

  background-color: orange;

  max-height: 0;

  overflow: hidden;

  transition: max-height 0.3s ease-in-out;

}


dd.answer {

  background-color: orange;

  max-height: 0;

  overflow: hidden;

  transition: max-height 0.3s ease-in-out;

  border-bottom: 1px dashed black;

}


dt.question {

  display: inline-flex;

  cursor: pointer;

  padding: 15px 0px;

  font-family: "Inter";

  font-weight: 400;

  font-size: 16px;

  transition: transform 0.2s linear;

  line-height: 150%;

  width: 100%;

}


/* arrow  */

dt.question:after {

  content: "\f055";

  font-family: "fontawesome";

  margin-right: 12px;

  padding-top: 3px;

}


@-moz-document url-prefix() {

  dt.question:after {

    margin-top: 0px;

  }

}


dt.question.is-open:after {

  content: "\f056";

}


dt.question:hover,

dt.question.is-open {

  transform: translateX(5px);

}

    <!-- accordion starts here -->


    <div class="container">

      <dl class="category">

        <h3 class="category_name">Lorem</h3>

<div class="category_content">

        <dt class="question"><h4>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium?</h4></dt>

        <dd class="answer">

          <p>

            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

          </p>

        </dd>


        <dt class="question"><h4>Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam?</h4></dt>

        <dd class="answer">

          <p>

            Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non.

          </p>

        </dd>


        <dt class="question"><h4>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</h4></dt>

        <dd class="answer">

          <p>

            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

          </p>

        </dd>


      </div>

      </dl>

          <dl class="category">

        <h3 class="category_name">Lorem2</h3>

<div class="category_content">

        <dt class="question"><h4>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium?</h4></dt>

        <dd class="answer">

          <p>

            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam.

          </p>

        </dd>


        <dt class="question"><h4>Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam?</h4></dt>

        <dd class="answer">

          <p>

            Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit.

          </p>

        </dd>


        <dt class="question"><h4>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</h4></dt>

        <dd class="answer">

          <p>

            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.

          </p>

        </dd>


      </div>

      </dl>

    </div>

    <!-- accordion ends here -->


查看完整回答
反對 回復(fù) 2023-05-19
  • 1 回答
  • 0 關(guān)注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號