溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

jquery如何實現手風琴展開效果

發布時間:2022-07-13 14:19:46 來源:億速云 閱讀:240 作者:iii 欄目:開發技術

這篇文章主要介紹“jquery如何實現手風琴展開效果”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“jquery如何實現手風琴展開效果”文章能幫助大家解決問題。

手風琴模式實現方式:

dom層代碼:

<div class="accordionWrap">
        <div class="wrap">
        <div class="title">
            <span>內容一</span>
            <span class="arrow slideTog"></span>
        </div>
        <div class="accordionCon">
            <div>
                <p>錦瑟無端五十弦,一弦一柱思華年。</p>
                <p>莊生曉夢迷蝴蝶,望帝春心托杜鵑。</p>
                <p>滄海月明珠有淚,藍田日暖玉生煙。</p>
                <p>此情可待成追憶?只是當時已惘然。</p>
            </div>
            <div class="moreCon" >
                <p>相見時難別亦難,東風無力百花殘。</p>
                <p>春蠶到死絲方盡,蠟炬成灰淚始干。</p>
                <p>曉鏡但愁云鬢改,夜吟應覺月光寒。</p>
                <p>蓬山此去無多路,青鳥殷勤為探看。</p>
            </div>
        </div>
        </div>
        <div class="wrap">
            <div class="title">
                <span>內容一</span>
                <span class="arrow slideTog"></span>
            </div>
            <div class="accordionCon">
                <div>
                    <p>錦瑟無端五十弦,一弦一柱思華年。</p>
                    <p>莊生曉夢迷蝴蝶,望帝春心托杜鵑。</p>
                    <p>滄海月明珠有淚,藍田日暖玉生煙。</p>
                    <p>此情可待成追憶?只是當時已惘然。</p>
                </div>
                <div class="moreCon" >
                    <p>相見時難別亦難,東風無力百花殘。</p>
                    <p>春蠶到死絲方盡,蠟炬成灰淚始干。</p>
                    <p>曉鏡但愁云鬢改,夜吟應覺月光寒。</p>
                    <p>蓬山此去無多路,青鳥殷勤為探看。</p>
                </div>
            </div>
        </div>
        <div class="wrap">
            <div class="title">
                <span>內容一</span>
                <span class="arrow slideTog"></span>
            </div>
            <div class="accordionCon">
                <div>
                    <p>錦瑟無端五十弦,一弦一柱思華年。</p>
                    <p>莊生曉夢迷蝴蝶,望帝春心托杜鵑。</p>
                    <p>滄海月明珠有淚,藍田日暖玉生煙。</p>
                    <p>此情可待成追憶?只是當時已惘然。</p>
                </div>
                <div class="moreCon" >
                    <p>相見時難別亦難,東風無力百花殘。</p>
                    <p>春蠶到死絲方盡,蠟炬成灰淚始干。</p>
                    <p>曉鏡但愁云鬢改,夜吟應覺月光寒。</p>
                    <p>蓬山此去無多路,青鳥殷勤為探看。</p>
                </div>
            </div>
        </div>
</div>

css代碼:

 .accordionWrap{
    width: 218px;
    background:#1890ff;
    border-radius: 4px;
    position:absolute;
    left: 10px;
    top: 50px;
    padding: 10px;
    box-sizing: border-box;
    .wrap{
        line-height: 18px;
     .title{
        span{
        font-size: 12px;
        font-family: SourceHanSansCN-Regular, SourceHanSansCN;
        font-weight: 400;
        color: #fff;
         }
           .arrow{
            width: 12px;
            height: 7px;
            background:url("../img/arrow.svg") no-repeat;
            background-size: 100% 100%;
            float:right;
            margin-top: 5px;
            transform: rotate(180deg);
            cursor: pointer;
            transition: all 0.5s;
        }
       .slideTogExchange {
            width: 12px;
            height: 7px;
            background: url('../img/arrow.svg') no-repeat;
            background-size: 100% 100%;
            float:right;
            margin-top: 10px;
            cursor: pointer;
            transform: rotate(0deg);
          }
     }
     .accordionCon{
         border-top: 1px dashed #45fff8;
         border-bottom: 1px solid #dddddd;
        p{
        font-size: 12px;
        font-family: SourceHanSansCN-Regular, SourceHanSansCN;
        font-weight: 400;
        color: #fff;
        }
        .moreCon{
            p{
            color: #45FFF8 !important;
            }
        }
        }
    }
 }

js操作dom的時候一定要注意層級之間的關系

 $(function () {
    // 點擊箭頭展開隱藏的內容
     $(".slideTog").click(function () {
     var hasClass = $(this).hasClass('slideTogExchange')
      if (hasClass) {
$(this).parent().siblings('.accordionCon').children('.moreCon').slideUp()
 $(this).removeClass('slideTogExchange')
 } else {           $(this).parent().siblings('.accordionCon').children('.moreCon').slideDown()
 $(this).addClass('slideTogExchange')
            }       $(this).parents('.wrap').siblings('.wrap').children('.accordionCon').children('.moreCon').slideUp().removeClass('slideTogExchange')     $(this).parents('.wrap').siblings('.wrap').find('.slideTog').removeClass('slideTogExchange')
        });
    })

實現效果如下:

jquery如何實現手風琴展開效果

關于“jquery如何實現手風琴展開效果”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識,可以關注億速云行業資訊頻道,小編每天都會為大家更新不同的知識點。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女