代码源自于:微信小程序示例官方

index.wxml

 <block wx:for-items="{{list}}" wx:key="{{item.id}}">
<view class="kind-list-item">
<view id="{{item.id}}" class="kind-list-item-hd {{item.open ? 'kind-list-item-hd-show' : ''}}" bindtap="kindToggle">
<view class="kind-list-text">{{item.name}}</view>
</view>
<view class="kind-list-item-bd {{item.open ? 'kind-list-item-bd-show' : ''}}">
<view class="navigator-box {{item.open ? 'navigator-box-show' : ''}}">
<block wx:for-items="{{item.pages}}" wx:for-item="page" wx:key="*item">
<navigator url="pages/{{page}}/{{page}}" class="navigator">
<view class="navigator-text">{{page}}</view>
<!-- icon -->
<view class="navigator-arrow"></view>
</navigator>
</block>
</view>
</view>
</view>
</block>

index.css

 .navigator-box {
opacity:;
position: relative;
background-color: #fff;
line-height: 1.41176471;
font-size: 34rpx;
transform: translateY(-50%);
transition: 0.3s;
} .navigator-box-show {
opacity:;
transform: translateY(0);
} .navigator {
padding: 20rpx 30rpx;
position: relative;
display: flex;
align-items: center;
} .navigator:before {
content: " ";
position: absolute;
left: 30rpx;
top:;
right: 30rpx;
height: 1px;
border-top: 1rpx solid #d8d8d8;
color: #d8d8d8;
} .navigator:first-child:before {
display: none;
} .navigator-text {
flex:;
} .navigator-arrow {
padding-right: 26rpx;
position: relative;
} .navigator-arrow:after {
content: " ";
display: inline-block;
height: 18rpx;
width: 18rpx;
border-width: 2rpx 2rpx 0 0;
border-color: #888;
border-style: solid;
transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
position: absolute;
top: 50%;
margin-top: -8rpx;
right: 28rpx;
} .kind-list-item {
margin: 20rpx 0;
background-color: #fff;
border-radius: 4rpx;
overflow: hidden;
border-bottom: 1px dashed #888;
} .kind-list-item:first-child {
margin-top:;
} .kind-list-text {
flex:;
} .kind-list-img {
width: 60rpx;
height: 60rpx;
} .kind-list-item-hd {
padding: 30rpx;
display: flex;
align-items: center;
transition: opacity 0.3s;
} .kind-list-item-hd-show {
opacity: 0.2;
} .kind-list-item-bd {
height:;
overflow: hidden;
} .kind-list-item-bd-show {
height: auto;
}

index.js

 Page({
data: {
list: [{
id: 'view',
name: '视图容器',
open: false,
pages: ['view', 'scroll-view', 'swiper', 'movable-view', 'cover-view']
}, {
id: 'content',
name: '基础内容',
open: false,
pages: ['text', 'icon', 'progress', 'rich-text']
}, {
id: 'form',
name: '表单组件',
open: false,
pages: ['button', 'checkbox', 'form', 'input', 'label', 'picker', 'picker-view', 'radio', 'slider', 'switch', 'textarea']
}, {
id: 'nav',
name: '导航',
open: false,
pages: ['navigator']
}, {
id: 'media',
name: '媒体组件',
open: false,
pages: ['image', 'audio', 'video', 'camera']
}, {
id: 'map',
name: '地图',
pages: ['map']
}, {
id: 'canvas',
name: '画布',
pages: ['canvas']
}, {
id: 'open',
name: '开放能力',
pages: ['ad', 'open-data', 'web-view']
}]
}, /**
* 收缩核心代码
*/
kindToggle(e) {
const id = e.currentTarget.id
const list = this.data.list
for (let i = 0, len = list.length; i < len; ++i) {
if (list[i].id === id) {
list[i].open = !list[i].open
} else {
list[i].open = false
}
} /**
* key和value名称一样时,可以省略
*
* list:list=>list
*/
this.setData({
list
})
}
})

点击下载源码:示例-小程序展开收缩列表

微信小程序 - 展开收缩列表的更多相关文章

  1. 微信小程序开发-新闻列表之新闻列表绑定

    微信小程序开发-新闻列表之新闻列表绑定开发教程: 1.效果图预览 2.准备工作 在拿到效果图后不要先急着去写代码,而是要去分析一下页面的整体结构,用什么方式定位和布局.小程序里建议使用flex布局,因 ...

  2. 微信小程序新闻信息列表展示

    微信小程序信息展示列表 wxml <!-- 轮播图 --> <view class='haibao' bindtap="seeDetail" id="{ ...

  3. 微信小程序信息展示列表

    微信小程序信息展示列表 效果展示: 代码展示: wxml <view class="head"> <view class="head_item" ...

  4. 基于微信小程序的用户列表点赞功能

    代码地址如下:http://www.demodashi.com/demo/13997.html 一.前言 (1).适合人群 1.微信小程序开发者 2.前端工程师 3.想入门学习小程序开发的人员 4.想 ...

  5. 图解微信小程序---获取电影列表

    图解微信小程序---获取电影列表 代码笔记 list跳转 第一步:编写前端页面获取相关的电影列表参数(对于显示参数不熟悉,可以先写js,通过console  Log的方式获取我们电影的相关数据字段,后 ...

  6. 微信小程序,我的英雄列表

    最近微信小程序炒得火热,就跟成都的这个房价一样.昨天我也尝试了一下,做了一个自己的英雄列表.今天将自己的制作过程记录于此. 1.下载微信开发者工具 官网链接:https://mp.weixin.qq. ...

  7. 微信小程序 - 文字收缩与展开

    wxml <view class='containers'> <text class="content {{ellipsis?'ellipsis':'unellipsis' ...

  8. 小程序展开收缩文字demo

    demo效果图: wxml 代码: <view class="{{ellipsis?'ellipsis':'unellipsis'}}">五险一金五五险一金险险一金五五 ...

  9. 微信小程序云开发-列表数据分页加载显示

    一.准备工作 1.创建数据库nums,向数据库中导入108条数据 2.修改数据库表nums的权限 二.新建页面ListPaginated 1.wxml文件 <!-- 显示列表数据 --> ...

随机推荐

  1. 【BZOJ 4169】 4169: Lmc的游戏 (树形DP)

    4169: Lmc的游戏 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 44  Solved: 25 Description RHL有一天看到lmc在 ...

  2. cocos2d-android 使用 cocos2d 绘图

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha cocos2d-android-1 https://github.com/ZhouWei ...

  3. CSS 笔记——导航栏、下拉菜单、提示工具

    8. 导航栏.下拉菜单.提示工具 (1)导航栏 垂直导航栏 <!DOCTYPE html> <html lang="en"> <head> &l ...

  4. 【枚举】【DFS序】Gym - 101617G - Rainbow Roads

    题意:一颗树,每条边有个颜色,一条路径被定义为“彩虹”,当且仅当其上没有长度大于等于2的同色子路径.一个结点被定义为“超级结点”,当且仅当从其发出的所有路径都是“彩虹”. 枚举所有长度为2,且同色的路 ...

  5. bzoj 3073: [Pa2011]Journeys -- 线段树优化最短路

    3073: [Pa2011]Journeys Time Limit: 20 Sec  Memory Limit: 512 MB Description     Seter建造了一个很大的星球,他准备建 ...

  6. php-streams扩展学习

    一. streams是干嘛的: 用于统一文件.网络.数据压缩等类文件操作方式,并为这些类文件操作提供一组通用的函数接口. 二. stream是具有流式行为的资源对象,这个对象有一个包装类 例如: pr ...

  7. [转]最流行的android组件大全

      目录(?)[+] 目录(?)[-] 最流行的android组件大全 UI组件 类库 游戏引擎 Android HTML5应用 最流行的android组件大全 最新更新文档请访问我的网站 Andro ...

  8. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

  9. 搭建MSSM框架(Maven+Spring+Spring MVC+MyBatis)

    https://github.com/easonjim/ssm-framework 先欠着,后续再进行讲解: 一.Spring内核集成 二.Spring MVC集成 三.MyBatis集成 四.代码生 ...

  10. How to make a combo box with fulltext search autocomplete support?

    I would like a user to be able to type in the second or third word from a TComboBoxitem and for that ...