小程序TAB列表切换内容动态变化,scrollview高度根据内容动态获取
滑动tab选项卡
一、在小程序里面tab选项卡是用的是自带的swiper组件,下面直接上代码
<view class="container">
<view class="tab">
<view class="tab-list {{currentTab==0? 'active':''}}" data-current="0" bindtap='switchNav'>运动专区</view>
<view class="tab-list {{currentTab==1? 'active':''}}" data-current="1" bindtap='switchNav'>美食专区</view>
</view>
<swiper current='{{currentTab}}' class="swiper-box" duration='300' bindchange='bindChange' style="height: {{clientHeight?clientHeight+'px':'auto'}}">
<!--运动专区 -->
<swiper-item class="swiper-content">
<scroll-view scroll-y="{{true}}" style="height: {{clientHeight?clientHeight+'px':'auto'}}">
<block wx:for="{{video}}" wx:key="video">
<!-- <template name="video-detail"> -->
<view class="video-detail-list">
<view class="original">
<text class="original-name">{{original}}</text>
<view class="original-video">
<video src="{{item.url}}"></video>
</view>
<view class="original-video-explain">
<text class="original-video-date">{{item.addtime}}</text>
<text class="original-video-name">{{item.title}}</text>
<view class="original-video-detail">
<text>{{originalContent}}</text>
</view>
</view>
</view>
</view>
</block>
</scroll-view>
</swiper-item>
<!--美食专区 -->
<swiper-item class="swiper-content">
<scroll-view scroll-y="{{true}}" style="height: {{clientHeight?clientHeight+'px':'auto'}}">
<block wx:for="{{video}}" wx:key="video">
<view class="video-detail-list">
<view class="original">
<text class="original-name">{{original}}</text>
<view class="original-video">
<video src="{{item.url}}"></video>
</view>
<view class="original-video-explain">
<text class="original-video-date">{{item.addtime}}</text>
<text class="original-video-name">{{item.title}}</text>
<view class="original-video-detail">
<text>{{originalContent}}</text>
</view>
</view>
</view>
</view>
</block>
</scroll-view>
</swiper-item>
</swiper>
</view>
ps:大家都知道小程序是不能操作DOM的,所以这里用getSystemInfo获取设备高度,scrollview在这里是一个内嵌的框架,列表在框架内滚动,它的高度其实就是屏幕的高度,不是里边列表项目的高度,
所以这里设置max-height等都是无效的。
样式代码:
.container{
width:100%;
height: 100%;
background:#eee;
}
/*tab切换导航 */
.tab{
width: 100%;
color:#666666;
height: 70rpx;
font-size:28rpx;
display: inline-block;
text-align: center;
background: #fff;
}
.tab-list{
height: 70rpx;
line-height: 70rpx;
width: 50%;
display: inline-block;
z-index: 1000;
}
.active{
border-bottom:4rpx solid #FD9D80;
}
.swiper-box{
width: 100%;
max-height:9999px;
display: block;
}
.video-detail-list{
margin-top:16rpx;
width:100%;
background: #fff;
}
.video-detail-list .original-name{
height: 80rpx;
line-height: 80rpx;
text-align: center;
display: block;
font-size:28rpx;
}
.original-name{
color:#999999;
}
.original-video{
text-align: center;
}
.original-video video{
width: 640rpx;
}
.original-video video{
border-radius:16rpx;
}
.original-video-explain{
width: 640rpx;
margin-left:50rpx;
}
.original-video-date{
font-size:28rpx;
color:#6C6C6C;
}
.original-video-date text{
display: inline-block;
}
.original-video-name{
text-align: center;
width: 55%;
margin-top:8rpx;
float:right;
font-size:28rpx;
color:#6C6C6C;
overflow: hidden; /* 超出自动隐藏 */
text-overflow:ellipsis; /* 文字隐藏后添加省略号 */
white-space:nowrap; /* 强制不换行 */
}
.original-video-detail{
color:#A1A1A1;
height: 30rpx;
font-size:20rpx;
/* margin-top:-10rpx; */
}
.original-video-detail text{
width: 100%;
display: -webkit-box;
word-break: break-all;
-webkit-box-orient: vertical;
-webkit-line-clamp:3;
overflow: hidden;
text-overflow:ellipsis;
color:#666;
}
js代码:
var videoUrl = 'http://t.jingduhealth.com/index/xcsvideo'
var app = getApp()
Page({
data: {
true:true,
video:[],
winWidth: 0,
winHeight: 0,
currentTab: 0, // tab切换
},
//tab导航条切换事件
bindChange:function(e){
var that = this;
that.setData({
currentTab: e.detail.current
})
},
switchNav:function(e){
var that = this;
if (this.data.currentTab === e.target.dataset.current){
return false;
}else{
that.setData({
currentTab: e.target.dataset.current
})
}
},
onLoad: function () {
var that = this;
//进入页面显示正在加载的图标
wx.showToast({
title: '正在加载中...',
icon: 'loading',
duration: 10000
})
wx.request({
url:videoUrl,
data:{},
header:{
'ContentType':'application/json'
},
success: function (res){
//获取到数据后隐藏正在加载图标
wx.hideLoading();
console.log(res.data)
that.setData({
video:res.data.slice(0,2) //获取的数据截取数组下标0-2的数据
})
}
})
//获取系统信息
wx.getSystemInfo({
success:function(res){
that.setData({
clientHeight: res.windowHeight //设备的高度等于scroll-view内容的高度
})
}
})
}
})
成功后的截图
小程序TAB列表切换内容动态变化,scrollview高度根据内容动态获取的更多相关文章
- 微信小程序Tab选项卡切换大集合
代码地址如下:http://www.demodashi.com/demo/14028.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...
- 微信小程序tab栏切换
Wxml代码:<view class="body"> <view class="nav bc_white"> <view clas ...
- 微信小程序 - tab+swiper切换(非组件)
无奈slot不支持循环,无法成为组件. 该模板适用于新闻等,点击下载示例:tabswiper
- 微信小程序--Tab栏切换的快速实现
上效果! wxss样式代码: .tabs-item.selected { color:rgba(,,,.); border-bottom:2px solid rgba(,,,.); } .tabs-i ...
- 微信小程序新闻列表功能(读取文件、template模板使用)
微信小程序新闻列表功能(读取文件.template) 不忘初心,方得始终.初心易得,始终难守. 在之前的项目基础上进行修改,实现读取文件内容作为新闻内容进行展示. 首先,修改 post.wxml 文件 ...
- 微信小程序左右滑动切换页面示例代码--转载
微信小程序——左右滑动切换页面事件 微信小程序的左右滑动触屏事件,主要有三个事件:touchstart,touchmove,touchend. 这三个事件最重要的属性是pageX和pageY,表示X, ...
- wepy小程序实现列表分页上拉加载(2)
第一篇:wepy小程序实现列表分页上拉加载(1) 本文接着上一篇内容: 4.优化-添加加载动画 (1)首先写加载动画的结构和样式 打开list.wpy文件 template结构代码: <temp ...
- wepy小程序实现列表分页上拉加载(1)
使用wepy开发微信小程序商城第一篇:项目初始化 使用wepy开发微信小程序商城第二篇:路由配置和页面结构 列表页效果图: 1.新建列表页 (1)在pages里面新建一个list.wpy文件 初始代码 ...
- 微信小程序tab切换,可滑动切换,导航栏跟随滚动实现
简介 看到今日头条小程序页面可以滑动切换,而且tab导航条也会跟着滚动,点击tab导航,页面滑动,切导航栏也会跟着滚动,就想着要怎么实现这个功能 像商城类商品类目如果做成左右滑动切换类目用户体验应该会 ...
随机推荐
- LeetCode-074-搜索二维矩阵
搜索二维矩阵 题目描述:编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值.该矩阵具有如下特性: 每行中的整数从左到右按升序排列. 每行的第一个整数大于前一行的最后一个整数. 示例说明请 ...
- pandas 中dataframe的操作
先用pandas生成数据, import numpy as npimport pandas as pddf= pd.DataFrame(np.arange(30).reshape(6,5),colum ...
- 跨平台书签同步-Xmarks
原文链接 Xmarks简介 Xmarks 是一款浏览器书签同步工具,它可以实现不同设备,不同浏览器之间的书签同步,并且是免费的. 有人会说,我们为什么需要一款专门的书签同步工具呢?Safari 自带的 ...
- 商品模型:SPU、商品、SKU概念模型设计
商品系统是电商SaaS.新零售SaaS最基础.最核心的系统之一.商品系统几乎需要支撑所有业务系统,商品详情.购物车.订单.履约.结算.售后.库存.供应链等,都需要依赖商品系统的能力.为了保障业务的稳定 ...
- 魅族mx3手机 固件升级方法
1.正常手机刷机,升级固件的方法 我今天3.5升4.2.8都提示固件损坏 后来我找客服 一定要用电脑下3.8固件 然后按住开机和音量+ 进入刷机模式 然后连接电脑 电脑会给你一个900mb的磁盘 拉进 ...
- 通过TCP Allocate连接数告警了解promethous-NodeExporter数据采集及相关知识扩散
1.问题由来 近日有环境告警如下:TCP Allocate连接数过多 很多资料告诉我们使用:netstat –ant | grep ^tcp | wc –l命令查询,但查询的值与告警中获取的只相差很大 ...
- 使用 Mosh 来优化 SSH 连接
1.什么是Mosh Mosh表示移动Shell(Mobile Shell),是一个用于从客户端跨互联网连接远程服务器的命令行工具.它能用于SSH连接,但是比Secure Shell功能更多.它是一个类 ...
- EVM
靶机设置 将靶机导入VirtualBox中,有时候导入VM会出错,扫描不到ip地址. kali:192.168.1.100 kali扫描获得ip地址:192.168.1.107 渗透测试 接着扫描端口 ...
- Java如何实现定时任务?
我是3y,一年CRUD经验用十年的markdown程序员常年被誉为优质八股文选手 挺早就规划了要引入分布式定时任务框架了,在年前austin就已经接入了,但代码过年一直都没写,文章也就一直拖到今天了 ...
- 多线程常用代码 Future Callable Runable
public class ThreadPoolTest { public static void main(String[] args) throws InterruptedException { E ...