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" 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')
        });
    })

实现效果如下:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • 基于jquery的slideDown和slideUp做手风琴

    手风琴 *{ padding:0; margin:0; } body{ background:#fafafa; font-size:12px; } .slider{ line-height:24px; width:700px; color:#7ecef4; margin:10px auto; background:#010e16; } .slider dt{ background:#f5f5d2; padding-left:30px; cursor:pointer; overflow:hidde

  • jquery插件制作 手风琴Panel效果实现

    首先我们还是创建一个html文件,里面包含如下的html结构. 复制代码 代码如下: <div id="pane-container"> <div class="pane"> <h1>first pane</h1> <p>this script should allow only one pane to be visible at a time.</p> </div> <div

  • jQuery Easyui使用(一)之可折叠面板的布局手风琴菜单

    先给大家看下效果图,效果图展示如下: 关键代码如下所示: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>首页</title> &l

  • Jquery组件easyUi实现手风琴(折叠面板)示例

    本文是为大家分享了Jquery easyUi手风琴效果,供大家参考,具体内容如下 效果图: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Basic Accordion - jQuery EasyUI Demo</title> <link rel="stylesheet" type="text/css&qu

  • jquery实现手风琴效果实例代码

    复制代码 代码如下: //jquery实现手风琴效果  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">  <head>  <

  • jquery超简单实现手风琴效果的方法

    本文实例讲述了jquery超简单实现手风琴效果的方法.分享给大家供大家参考.核心代码如下: $("#accordion .expanded").hide(); $("a.opening").click(function(){ $(this).next().slideToggle('fast', function(){ $(this).prev("a.opening").toggleClass("active"); }); re

  • jquery手风琴特效插件

    手风琴效果是项目中使用频率较高的一种效果,原来项目一直都在用easyui的,临近年末,试着自己写了一个 css样式 复制代码 代码如下: /* CSS Document */ body {     margin: 0 auto;     padding: 0 auto;     font-size: 9pt;     font-family: 微软雅黑, 宋体, Arial, Helvetica, Verdana, sans-serif; } .accordion {     padding-l

  • jQuery实现的简单手风琴效果示例

    本文实例讲述了jQuery实现的简单手风琴效果.分享给大家供大家参考,具体如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.jb51.net jQuery手风琴效果</title> <style> .wrap{ width: 200px;height: auto;margin:5

  • jQuery制作效果超棒的手风琴折叠菜单

    拉风的jQuery制作的手风琴折叠菜单,效果非常不错!这里是之前版本的改进版,主要是jquery代码改进 演示图: main.js $(function(){ var tmp = null, $title = $('.title'), $con = $('.title > ul'); $title.click(function(){ $(tmp).children('ul').slideUp().end().children('.arrow').removeClass('arrow-up');

  • 基于Jquery代码实现手风琴菜单

    先给大家展示效果图: 先看页面代码,列表的嵌套: <div id="menuDiv"> <ul id="menu"> <li class="parentLi"> <span>B</span> <ul class="childrenUl"> <li class="childrenLi"><span>C</sp

随机推荐