滑动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高度根据内容动态获取的更多相关文章

  1. 微信小程序Tab选项卡切换大集合

    代码地址如下:http://www.demodashi.com/demo/14028.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...

  2. 微信小程序tab栏切换

    Wxml代码:<view class="body"> <view class="nav bc_white"> <view clas ...

  3. 微信小程序 - tab+swiper切换(非组件)

    无奈slot不支持循环,无法成为组件. 该模板适用于新闻等,点击下载示例:tabswiper

  4. 微信小程序--Tab栏切换的快速实现

    上效果! wxss样式代码: .tabs-item.selected { color:rgba(,,,.); border-bottom:2px solid rgba(,,,.); } .tabs-i ...

  5. 微信小程序新闻列表功能(读取文件、template模板使用)

    微信小程序新闻列表功能(读取文件.template) 不忘初心,方得始终.初心易得,始终难守. 在之前的项目基础上进行修改,实现读取文件内容作为新闻内容进行展示. 首先,修改 post.wxml 文件 ...

  6. 微信小程序左右滑动切换页面示例代码--转载

    微信小程序——左右滑动切换页面事件 微信小程序的左右滑动触屏事件,主要有三个事件:touchstart,touchmove,touchend. 这三个事件最重要的属性是pageX和pageY,表示X, ...

  7. wepy小程序实现列表分页上拉加载(2)

    第一篇:wepy小程序实现列表分页上拉加载(1) 本文接着上一篇内容: 4.优化-添加加载动画 (1)首先写加载动画的结构和样式 打开list.wpy文件 template结构代码: <temp ...

  8. wepy小程序实现列表分页上拉加载(1)

    使用wepy开发微信小程序商城第一篇:项目初始化 使用wepy开发微信小程序商城第二篇:路由配置和页面结构 列表页效果图: 1.新建列表页 (1)在pages里面新建一个list.wpy文件 初始代码 ...

  9. 微信小程序tab切换,可滑动切换,导航栏跟随滚动实现

    简介 看到今日头条小程序页面可以滑动切换,而且tab导航条也会跟着滚动,点击tab导航,页面滑动,切导航栏也会跟着滚动,就想着要怎么实现这个功能 像商城类商品类目如果做成左右滑动切换类目用户体验应该会 ...

随机推荐

  1. selenium+python安装

    整理了下selenium+python环境搭建,搭建了很多次但每次都还是手忙脚乱,今天用心整理下 selenium 是用于测试 Web 应用程序用户界面 (UI) 的常用框架,并且 Selenium ...

  2. Redis原理再学习05:数据结构-整数集合intset

    intset介绍 intset 整数集合,当一个集合只有整数元素,且元素数量不多时,Redis 就会用整数集合作为集合键的底层实现. redis> SADD numbers 1 3 5 7 9 ...

  3. Dapr 弹性的策略

    云原生应用需要处理 云中很容易出现瞬时故障.原因在以下文档 暂时性故障处理[1] 中有具体说明. 任何环境.任何平台或操作系统以及任何类型的应用程序都会发生暂时性故障. 在本地基础结构上运行的解决方案 ...

  4. 二级py--day1

    1.py基础篇 解释:因为在python语言中存在一个不确定尾数问题. 因为浮点数是以二进制形式储存在计算机内部的,受限于宽度,二进制数并不完全等于其浮点数本身,只能说接近.所以0.1+0.2==0. ...

  5. Python:pyglet学习(1):想弄点3D,还发现了pyglet

    某一天,我突然喜欢上了3D,在一些scratch教程中见过一些3D引擎,找了一个简单的,结果z轴太大了,于是网上一搜,就发现了pyglet 还是先讲如何启动一个窗口 先看看官网: Creating a ...

  6. CF1327F题解

    首先第一步,位运算拆位.变为一个区间的 \(And\) 为 \(0\) 或 \(1\). 如果 \(And\) 为 \(1\),那么所有数都需要为 \(1\),否则为 \(0\). 我们把所有可能为 ...

  7. Springboot项目 配置数据库连接属性后,启动项目报错

    Springboot项目 配置数据库连接属性后,启动项目报错,错误如下: 错误原因分析: 1.连接信息配置错误 当使用properties为配置文件时,如图所示,上面的 spring.datasour ...

  8. ArcMap进行天空开阔度(SVF)分析

    这里的SVF并不是生物学或医学的(Stromal Vascular Fraction),而是指GIS中的(Sky View Factor,SVF),即为(城市)天空开阔度. 城市天空开阔度(Sky V ...

  9. 超详细GoodSync11.2.7.8单机、两个服务器之间的文件同步使用教程

    GoodSync安装教程 第一步:双机GoodSync_v11.2.7.8.exe文件 链接:https://pan.baidu.com/s/16FVater4f9vu07QiGGIK9A 提取码:b ...

  10. 网络监听HTTP协议信息实验

    一.开启环境 登录web服务器,在服务器中开启phpstudy服务器环境. 在操作机中打开目标站[Web服务器IP地址]地址.安装wordpress,数据库名:wordpress,用户名root 密码 ...