亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

我如何使用純 JS 使下拉菜單順利顯示?

我如何使用純 JS 使下拉菜單順利顯示?

開心每一天1111 2022-12-29 13:50:12
我做了一個下拉菜單,display: none;當它被點擊時,下拉部分有JS給它的類motherHover,display: grid;讓它可見。但問題是菜單出現了One-shot。純JS如何讓下拉菜單流暢顯示?function fgf(){    var hoverElement = document.querySelector(".father"),    tragtedElement = document.querySelector("#dds");    tragtedElement.classList.toggle("motherHover");}ul{    list-style: none;}.father{}.mother{    display: none;}.asd {    display: grid;}.motherHover{    display: grid;}<link href="https://meyerweb.com/eric/tools/css/reset/reset200802.css" rel="stylesheet"/>    <ul>        <li class="father" onclick="fgf()">            <button>                Drop Menu            </button>        </li>        <li id="dds" class="mother" >            <ul class="asd">                <i>g</i>                <i>g</i>                <i>g</i>                <i>g</i>                <i>g</i>            </ul>        </li>    </ul>
查看完整描述

1 回答

?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

它通常完成max-height和過渡。


function fgf(){

    let asd = document.querySelector(".asd");

    asd.classList.toggle("open");

}

ul{

    list-style: none;

}

.asd {

    display: grid;

    max-height: 0;

    transition: max-height 500ms;

    overflow: hidden;

    background: green;

    color: white;

}

.open {

   max-height: 100px !important;

}

<link href="https://meyerweb.com/eric/tools/css/reset/reset200802.css" rel="stylesheet"/>


    <ul>

        <li class="father" onclick="fgf()">

            <button>

                Drop Menu

            </button>

        </li>

        <li id="dds" class="mother" >

            <ul class="asd">

                <i>g</i>

                <i>g</i>

                <i>g</i>

                <i>g</i>

                <i>g</i>

            </ul>

        </li>

    </ul>


查看完整回答
反對 回復 2022-12-29
  • 1 回答
  • 0 關注
  • 97 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號