当前位置: 首页 > Web前端 > HTML5

小程序TAB列表内容动态变化,scrollview高度根据内容动态获取

时间:2023-04-05 20:50:13 HTML5

滑动tab标签1.小程序中的tab标签使用了内置的swiper组件,直接上传下面的代码运动区美食区{{original}}<viewclass="original-video">{{item.addtime}}{{item.title}}{{originalContent}}{{original}}{{item.添加时间}}{{item.标题}}{{originalContent}}ps:大家都知道小程序是不能操作DOM的,所以这里使用getSystemInfo来获取设备的高度,scrollview是一个内嵌的这里有一个frame,列表在frame中滚动,它的高度其实就是屏幕的高度,不是里面listitem的高度,所以这里设置max-height等是无效的。样式代码:.container{width:100%;高度:100%;background:#eee;}/*tab切换导航*/.tab{width:100%;颜色:#666666;高度:70rpx;字体大小:28rpx;显示:内联块;文本对齐:居中;背景:#fff;}.tab-list{高度:70rpx;行高:70rpx;宽度:50%;显示:内联块;z-index:1000;}.active{border-bottom:4rpxsolid#FD9D80;}.swiper-box{width:100%;最大高度:9999px;显示:块;}.video-detail-list{margin-top:16rpx;宽度:100%;背景:#fff;}.video-detail-list.original-name{高度:80rpx;行高:80rpx;文本对齐:居中;显示:块;font-size:28rpx;}.original-name{color:#999999;}.original-video{text-align:center;}.original-videovideo{width:640rpx;}.original-videovideo{边框半径:16rpx;}.original-video-explain{宽度:640rpx;margin-left:50rpx;}.original-video-date{字体大小:28rpx;颜色:#6C6C6C;}.original-video-datetext{display:inline-block;}.original-video-name{text-align:center;宽度:55%;保证金顶部:8rpx;浮动:对;字体大小:28rpx;颜色:#6C6C6C;溢出:隐藏;/*超越自动隐藏*/text-overflow:ellipsis;/*在文本隐藏后添加一个省略号*/white-space:nowrap;/*强制不换行*/}.original-video-detail{color:#A1A1A1;高度:30rpx;字体大小:20rpx;/*顶部边距:-10rpx;*/}.original-video-detailtext{宽度:100%;显示:-webkit-box;word-break:break-all;-webkit-box-orient:垂直;-webkit-line-clamp:3;溢出:隐藏;文本溢出:省略号;color:#666;}js代码:varvideoUrl='http://t.jingduhealth.com/index/xcsvideo'varapp=getApp()Page({data:{true:true,video:[],winWidth:0,winHeight:0,currentTab:0,//tab切换},//tab导航栏切换事件bindChange:function(e){varthat=this;that.setData({currentTab:e.detail.current})},switchNav:function(e){varthat=this;if(this.data.currentTab===e.target.dataset.current){returnfalse;}else{that.setData({currentTab:e.target.dataset。当前的})}},onLoad:function(){varthat=this;//进入页面显示加载图标wx.showToast({title:'Loading...',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内容的高度})}})}})成功后截图