- Framework7 教程
- Framework7 - 首页
- Framework7 - 概览
- Framework7 - 环境
- Framework7 组件
- Framework7 - 布局
- Framework7 - 导航栏
- Framework7 - 工具栏
- Framework7 - 搜索栏
- Framework7 - 状态栏
- Framework7 - 侧边栏
- Framework7 - 内容块
- Framework7 - 网格布局
- Framework7 - 覆盖层
- Framework7 - 预加载器
- Framework7 - 进度条
- Framework7 - 列表视图
- Framework7 - 手风琴
- Framework7 - 卡片
- Framework7 - 芯片
- Framework7 - 按钮
- Framework7 - 操作按钮
- Framework7 - 表单
- Framework7 - 标签页
- Framework7 - Swiper 滑块
- Framework7 - 照片浏览器
- Framework7 - 自动完成
- Framework7 - 选择器
- Framework7 - 日历
- Framework7 - 刷新
- Framework7 - 无限滚动
- Framework7 - 消息
- Framework7 - 消息栏
- Framework7 - 通知
- Framework7 - 延迟加载
- Framework7 样式
- Framework7 - 色彩主题
- Framework7 - 分割线
- Framework7 模板
- Framework7 - 模板概览
- Framework7 - 自动编译
- Framework7 - Template7 页面
- Framework7 快速点击
- Framework7 - 活动状态
- Framework7 - 长按事件
- Framework7 - 触摸水波纹
- Framework7 有用资源
- Framework7 - 快速指南
- Framework7 - 有用资源
- Framework7 - 讨论
Framework7 - 手风琴
描述
手风琴是一个图形控件元素,显示为一个堆叠的项目列表。每个手风琴可以展开或拉伸以显示与该手风琴关联的内容。
可折叠布局
当您使用单个独立的可折叠元素时,您需要省略accordion-list包装器元素。
以下是可折叠布局的结构 -
<!-- Single collapsible element ------> <div class = "accordion-item"> <div class = "accordion-item-toggle"></div> <div class = "accordion-item-content"></div> </div> <!-- Separate collapsible element --> <div class = "accordion-item"> <div class = "accordion-item-toggle"></div> <div class = "accordion-item-content"></div> </div>
以下类用于 Framework7 中的手风琴 -
序号 | 类 & 描述 |
---|---|
1 | accordion-list 这是一个可选类,包含一组手风琴项目列表。 |
2 | accordion-item 这是单个手风琴项目所需的类。 |
3 | accordion-item-toggle 这是用于展开手风琴项目内容的必需类。 |
4 | accordion-item-content 这是用于隐藏的手风琴项目内容的必需类。 |
5 | accordion-item-expanded 它是一个展开的手风琴项目。 |
手风琴 JavaScript API
JavaScript API 方法用于以编程方式打开和关闭手风琴。
它包含以下 JavaScript API 方法 -
myApp.accordionOpen(item) - 用于打开手风琴。
myApp.accordionClose(item) - 用于关闭手风琴。
myApp.accordionToggle(item) - 用于切换手风琴。
所有方法都包含名为item的参数,它是 accordion-item 的 HTML 或字符串元素。
手风琴事件
手风琴包含四个事件,如以下表格中列出 -
序号 | 事件 | 目标 & 描述 |
---|---|---|
1 | open | 手风琴项目 当您打开动画时,将触发此事件。 |
2 | opened | 手风琴项目 当动画打开完成时,将触发此事件。 |
3 | close | 手风琴项目 当您关闭动画时,将触发此事件。 |
4 | closed | 手风琴项目 当动画关闭完成时,将触发此事件。 |
手风琴列表视图
在手风琴列表视图中,您可以使用item-link元素代替accordion-toggle。
<div class = "list-block accordion-list"> <ul> <li class = "accordion-item"> <a href = "" class = "item-link item-content"> <div class = "item-inner"> <div class = "item-title">1st Item</div> </div> </a> <div class = "accordion-item-content">Content for 1st Item...</div> </li> <li class = "accordion-item"> <a href = "" class = "item-link item-content"> <div class = "item-inner"> <div class = "item-title">2nd Item</div> </div> </a> <div class = "accordion-item-content">Content for 2nd Item...</div> </li> </ul> </div>
示例
以下示例演示了在 Framework7 中使用手风琴 -
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <title>Accordion</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css"> </head> <body> <div class="views"> <div class="view view-main"> <div class="pages"> <div data-page="home" class="page navbar-fixed"> <div class="navbar"> <div class="navbar-inner"> <div class="left"> </div> <div class="center">Accordion</div> <div class="right"> </div> </div> </div> <div class="page-content"> <div class="content-block-title">List of Programming Lagauges</div> <div class="list-block accordion-list"> <ul> <li class="accordion-item"> <a href="#" class="item-content item-link"> <div class="item-inner"> <div class="item-title">C</div> </div> </a> <div class="accordion-item-content"> <div class="content-block"> <p>C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers.</p> </div> </div> </li> <li class="accordion-item"> <a href="#" class="item-content item-link"> <div class="item-inner"> <div class="item-title">C++</div> </div> </a> <div class="accordion-item-content"> <div class="content-block"> <p>C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This reference will take you through simple and practical approach while learning C++ Programming language. </p> </div> </div> </li> <li class="accordion-item"> <a href="#" class="item-content item-link"> <div class="item-inner"> <div class="item-title">Java</div> </div> </a> <div class="accordion-item-content"> <div class="content-block"> <p>Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial gives a complete understanding of Java. This reference will take you through simple and practical approach while learning Java Programming language. </p> </div> </div> </li> </ul> </div> <div class="content-block-title">Separate Collapsibles</div> <div class="list-block"> <ul> <li class="accordion-item"> <a href="#" class="item-content item-link"> <div class="item-inner"> <div class="item-title">C</div> </div> </a> <div class="accordion-item-content"> <div class="content-block"> <p >C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers.</p> </div> </div> </li> <li class="accordion-item"> <a href="#" class="item-content item-link"> <div class="item-inner"> <div class="item-title">C++</div> </div> </a> <div class="accordion-item-content"> <div class="content-block"> <p>C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This reference will take you through simple and practical approach while learning C++ Programming language. </p> </div> </div> </li> <li class="accordion-item"> <a href="#" class="item-content item-link"> <div class="item-inner"> <div class="item-title">Java</div> </div> </a> <div class="accordion-item-content"> <div class="content-block"> <p>Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial gives a complete understanding of Java. This reference will take you through simple and practical approach while learning Java Programming language. </p> </div> </div> </li> </ul> </div> <div class="content-block-title">Custom Accordion</div> <div class="content-block accordion-list custom-accordion"> <div class="accordion-item"> <div class="accordion-item-toggle"><i class="icon icon-plus">+</i><i class="icon icon-minus">-</i><span>C</span></div> <div class="accordion-item-content"> <p>C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers.</p> </div> </div> <div class="accordion-item"> <div class="accordion-item-toggle"><i class="icon icon-plus">+</i><i class="icon icon-minus">-</i><span>C++</span></div> <div class="accordion-item-content"> <p>C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This reference will take you through simple and practical approach while learning C++ Programming language. </p> </div> </div> <div class="accordion-item"> <div class="accordion-item-toggle"><i class="icon icon-plus">+</i><i class="icon icon-minus">-</i><span>Java</span></div> <div class="accordion-item-content"> <p>Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial gives a complete understanding of Java. This reference will take you through simple and practical approach while learning Java Programming language. </p> </div> </div> </div> </div> </div> </div> </div> </div> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script> <style>.custom-accordion{padding-left:0;padding-right:0;}.custom-accordion .accordion-item-toggle{padding:0px 15px;height:44px;line-height:44px;font-size:17px;color:#000;border-bottom:1px solid rgba(0,0,0,0.15);cursor:pointer;}.custom-accordion .accordion-item-toggle:active{background:rgba(0,0,0,0.15);}.custom-accordion .accordion-item-toggle span{display:inline-block;margin-left:15px;}.custom-accordion .accordion-item:last-child .accordion-item-toggle{border-bottom:none;}.custom-accordion .icon-plus,.custom-accordion .icon-minus{display:inline-block;width:22px;height:22px;border:1px solid #000;border-radius:100%;line-height:20px;text-align:center;}.custom-accordion .icon-minus{display:none;}.custom-accordion .accordion-item-expanded .icon-minus{display:inline-block;}.custom-accordion .accordion-item-expanded .icon-plus{display:none;}.custom-accordion .accordion-item-content{padding:0px 15px;}</style> <script> // here initialize the app var myApp = new Framework7(); // If your using custom DOM library, then save it to $$ variable var $$ = Dom7; // Add the view var mainView = myApp.addView('.view-main', { // enable the dynamic navbar for this view: dynamicNavbar: true }); </script> </body> </html>
输出
让我们执行以下步骤来查看上面给出的代码是如何工作的 -
将上面给出的 HTML 代码保存为accordion.html文件到您的服务器根文件夹中。
打开此 HTML 文件,地址为 https://127.0.0.1/accordion.html,输出结果如下所示。
该示例提供了可折叠布局,可以展开以显示与手风琴关联的内容。