jquery實現(xiàn)手風琴展開效果
更新時間:2022年07月08日 15:54:28 作者:小小小菜鳥1997
這篇文章主要為大家詳細介紹了jquery實現(xiàn)手風琴展開效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了jquery實現(xiàn)手風琴展開效果的具體代碼,供大家參考,具體內容如下
手風琴模式實現(xiàn)方式:
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" style="display:none"> ? ? ? ? ? ? ? ? <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" style="display:none"> ? ? ? ? ? ? ? ? ? ? <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" style="display:none"> ? ? ? ? ? ? ? ? ? ? <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')
? ? ? ? });
? ? })實現(xiàn)效果如下:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
淺析jQuery(function(){})與(function(){})(jQuery)之間的區(qū)別
本篇文章主要是對jQuery(function(){})與(function(){})(jQuery)之間的區(qū)別進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01
通過jsonp獲取json數(shù)據(jù)實現(xiàn)AJAX跨域請求
JSON 可通過 JavaScript 進行解析,JSON 數(shù)據(jù)可使用 AJAX 進行傳輸,這篇文章主要介紹了通過jsonp獲取json數(shù)據(jù)(實現(xiàn)AJAX跨域請求),有興趣的可以了解一下。2017-01-01
使用struts2+Ajax+jquery驗證用戶名是否已被注冊
這篇文章主要介紹了使用struts2+Ajax+jquery驗證用戶名是否已被注冊的相關資料,需要的朋友可以參考下2016-03-03
jQuery獲取attr()與prop()屬性值的方法及區(qū)別介紹
這篇文章主要介紹了jQuery獲取attr()與prop()屬性值的方法及區(qū)別介紹的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07

