核心代码
- 发布:2021-01-16 15:00
- 更新:2021-06-05 08:54
- 阅读:1171
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: macOS Big sur 11.1
HBuilderX类型: 正式
HBuilderX版本号: 3.0.5
手机系统: Android
手机系统版本号: Android 11
手机厂商: 华为
手机机型: mate30 5G
页面类型: nvue
打包方式: 离线
项目创建方式: HBuilderX
示例代码:
操作步骤:
使用安卓系统手机运行app,从首页切换到问题页面时不时会出现自动吸顶的情况。使用的是官方插件,
链接:https://ext.dcloud.net.cn/plugin?id=2128
我的联系方式微信:yunyi360
使用安卓系统手机运行app,从首页切换到问题页面时不时会出现自动吸顶的情况。使用的是官方插件,
链接:https://ext.dcloud.net.cn/plugin?id=2128
我的联系方式微信:yunyi360
预期结果:
预期结果的照片我放在文件里
预期结果的照片我放在文件里
实际结果:
实际结果的照片我放在文件里
实际结果的照片我放在文件里
bug描述:
<template>
<list :id="pageId" class="page" :bounce="false" fixFreezing="true" @scroll="onScroll">
<cell id="head">
<!-- 头部 -->
<view class="header">
<header-page></header-page>
</view>
<!-- 头部 end-->
<!-- 滑动区 -->
<scroll-view scroll-x="true" class="scroll" show-scrollbar="false">
<view class="scroll-view" v-for="(item,index) in scrollBut" :key="'scrollBut' + index">
<image class="scroll-view-image" :src="item.image"></image>
<text class="scroll-view-text">#{{item.title}}</text>
</view>
</scroll-view>
<!-- 滑动区 end-->
<!-- 四个按钮区 -->
<view class="box2">
<view class="box2-1" v-for="(nav, index5) in buttonArray" :key="index5" @tap="toNavList(nav)">
<view class="box2-1-2">
<image class="box2-1-2-img" lazy-load='true' fade-show='true' :src="nav.icon" mode="widthFix"></image>
<text class="box2-1-2-text">{{ nav.title }}</text>
</view>
</view>
</view>
<!-- 四个按钮区 end-->
</cell>
<!-- 展示校园内容cell -->
<cell>
<view class="tabs" :style="'height:' + pageHeight + 'px'">
<scroll-view ref="tabbar1" id="tab-bar" class="tab-bar" :scroll="false" :scroll-x="true" :show-scrollbar="false"
:scroll-into-view="scrollInto">
<!-- 滑动选项卡标题左右滚动 -->
<view ref="tabbar1" id="tab-bar" class="tab-bar" style="flex-direction: column;">
<view style="flex-direction: row;">
<!-- 标题 -->
<view class="uni-tab-item" v-for="(tab,index) in tabList" :key="tab.id" :id="tab.id" :ref="'tabitem'+index"
:data-id="index" :data-current="index" @click="ontabtap">
<text class="uni-tab-item-title" :class="tabIndex==index ? 'uni-tab-item-title-active' : ''">{{tab.name}}</text>
</view>
<!-- 标题 end-->
</view>
<view class="scroll-view-indicator">
<!-- 标题下,滑动的线 -->
<view ref="underline" class="scroll-view-underline" :class="isTap ? 'scroll-view-animation':''" :style="{left: indicatorLineLeft + 'px', width: indicatorLineWidth + 'px'}"></view>
</view>
</view>
</scroll-view>
<!-- <view class="tab-bar-line"></view>分隔线 -->
<swiper class="tab-view" id="tab-bar-view" :current="tabIndex" :duration="300" @change="onswiperchange" @transition="onswiperscroll"
@animationfinish="animationfinish" @onAnimationEnd="animationfinish">
<!-- swiper-page左右滑动视图 -->
<swiper-item class="swiper-item" v-for="(page, index) in tabList" :key="index">
<swiper-page class="swiper-page" :pid="page.pageid" :parentId="pageId" ref="page"></swiper-page>
</swiper-item>
</swiper>
</view>
</cell>
</list>
</template>
<script>
// #ifdef APP-PLUS
const dom = weex.requireModule('dom');
// #endif
// 缓存每页最多
const MAX_CACHE_DATA = 100;
// 缓存页签数量
const MAX_CACHE_PAGE = 3;
const TAB_PRELOAD_OFFSET = 1; //选项卡预加载偏移
import swiperPage from './swiper-page.nvue'; //显示内容list组件
import headerPage from './header-Page.nvue'; //显示校园组件
import showData from '../../../common/showData.js'
import jsonData from '../../../common/jsonData.js'
export default {
components: {
swiperPage,
headerPage
},
data() {
return {
scrollBut:jsonData.button1,
btnName: ['打印', '哈哈', '快递', '的健康和'],
tabList: showData.tabList2,
tabIndex: 0,
cacheTab: [],
scrollInto: "",
indicatorLineLeft: 0,
indicatorLineWidth: 0,
isTap: false,//设置标题下,滑动的线
showTitleView: true,
pageHeight: 300,
pageId: "page",
// 中部四个按钮数组
buttonArray: showData.button1,
}
},
onLoad() {
// uni.navigateTo({
// url: './FindNotice/index',
// success: res => {},
// fail: () => {},
// complete: () => {}
// });
this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
},
onReady() {
// this.pageHeight = uni.getSystemInfoSync().windowHeight - 44 - uni.getSystemInfoSync().statusBarHeight; //导航栏高度固定为 44px,在减去状态栏的高度
this.pageHeight = uni.getSystemInfoSync().windowHeight;
this._lastTabIndex = 0;
this._touchTabIndex = 0;
this._headHeight = 100;
this.swiperWidth = 0;
this.tabbarWidth = 0;
this.tabListSize = {};
this.pageList = this.$refs.page;
console.log("gadga")
setTimeout(()=>{
this.selectorQuery();
},600)
},
methods: {
//跳转
toNavList(item){
console.log(item.url);
uni.navigateTo({
url: item.url
});
},
//滚动监听 设置透明导航栏
onScroll(e){
let color = 'rgba(250,250,250,0)'
if (-e.contentOffset.y > 160){
color = 'rgba(255, 255, 255, 1.0)'
}else{
color = 'rgba(255,255,255,' + -e.contentOffset.y/160 + ')'
}
if (-e.contentOffset.y ===0){
uni.setNavigationBarTitle({
title:' '
})
uni.setNavigationBarColor({
frontColor:'#ffffff',
backgroundColor:color
})
return;
}
uni.setNavigationBarTitle({
title:"Hi校园"
})
uni.setNavigationBarColor({
frontColor:'#000000',
backgroundColor:color
})
},
//在选项卡上点击
ontabtap(e) {
let index = e.target.dataset.current || e.currentTarget.dataset.current;
//let offsetIndex = this._touchTabIndex = Math.abs(index - this._lastTabIndex) > 1;
this.isTap = true;
var currentSize = this.tabListSize[index];
this.updateIndicator(currentSize.left, currentSize.width); //更新指标
this._touchTabIndex = index;
this.switchTab(index);
},
//滑动视图时更改选项卡的位置
onswiperchange(e) {
this.i = e.detail.current //判断用户使用的是新鲜事(0)还是视频(1)
if (this.dataList[this.i].length == 0) {
this.selectPage()
}
},
//滑动滚动
onswiperscroll(e) {
if (this.isTap) {
return;
}
var offsetX = e.detail.dx; //偏移
var preloadIndex = this._lastTabIndex;
if (offsetX > TAB_PRELOAD_OFFSET) {
preloadIndex++;
} else if (offsetX < -TAB_PRELOAD_OFFSET) {
preloadIndex--;
}
//preloadIndex:预紧指数
if (preloadIndex === this._lastTabIndex || preloadIndex < 0 || preloadIndex > this.pageList.length - 1) {
return;
}
var percentage = Math.abs(this.swiperWidth / offsetX);
var currentSize = this.tabListSize[this._lastTabIndex]; //当前所在滑块的current:index
var preloadSize = this.tabListSize[preloadIndex];
var lineL = currentSize.left + (preloadSize.left - currentSize.left) / percentage;
var lineW = currentSize.width + (preloadSize.width - currentSize.width) / percentage;
this.updateIndicator(lineL, lineW);
},
//动画完成
animationfinish(e) {
let index = e.detail.current;
if (this._touchTabIndex === index) {
this.isTap = false;
}
this._lastTabIndex = index;
this.switchTab(index); //切换标签
this.updateIndicator(this.tabListSize[index].left, this.tabListSize[index].width); //更新指标
},
//选择器查询
selectorQuery() {
let cc = 0
var aa = uni.upx2px(88);
new Promise(resolve => {
uni.createSelectorQuery().in(this).select('#head').boundingClientRect().exec(rect => {
resolve(rect[0].height)
});
}).then(res=>{
return;
this._headHeight = res - this.statusBarHeight - aa
// this._headHeight = res
console.log(this._headHeight);
})
// 查询 tabbar 宽度
uni.createSelectorQuery().in(this).select('#tab-bar').boundingClientRect().exec(rect => {
this.tabbarWidth = rect[0].width;
});
// 查询 tabview 宽度
uni.createSelectorQuery().in(this).select('#tab-bar-view').boundingClientRect().exec(rect => {
this.swiperWidth = rect[0].width;
});
// 因 nvue 暂不支持 class 查询
var queryTabSize = uni.createSelectorQuery().in(this); //可以在这个实例上使用 uni.createSelectorQuery() 等方法选择节点
for (var i = 0; i < this.tabList.length; i++) {
queryTabSize.select('#' + this.tabList[i].id).boundingClientRect(); //选择需要查询的信息 boundingClientRect
}
queryTabSize.exec(rects => { //查询标签页大小
rects.forEach((rect) => {
this.tabListSize[rect.dataset.id] = rect;
})
this.updateIndicator(this.tabListSize[this.tabIndex].left, this.tabListSize[this.tabIndex].width);
this.switchTab(this.tabIndex);
});
},
//更新指标
updateIndicator(left, width) {
this.indicatorLineLeft = left + 20;
this.indicatorLineWidth = width - 40;
},
//切换标签
switchTab(index) {
this.pageList[index].setScrollRef(this._headHeight);
if (this.tabIndex === index) {
return;
}
this.tabIndex = index;
this.scrollTabTo(index);
},
//当滑动视图时,选项卡置顶
scrollTabTo(index) {
const el = this.$refs['tabitem' + index][0];
let offset = 0;
// TODO fix ios offset
if (index > 0) {
offset = this.tabbarWidth / 2 - this.tabListSize[index].width / 2;
if (this.tabListSize[index].right < this.tabbarWidth / 2) {
offset = this.tabListSize[0].width;
}
}
console.log("选项卡置顶")
dom.scrollToElement(el, {//scrollToElement:让页面滚动到 ref 对应的组件,这个 API 只能用于可滚动组件的子节点
offset: -offset
});
},
//加载标签数据
loadTabData(index) {
this.pageList[index].loadData();
},
//清除标签数据
clearTabData(index) {
this.pageList[index].clear();
}
}
}
</script>
<style>
.activi{
position: fixed;
top: 120rpx;
width: 750rpx;
height: 80rpx;
background-color: #09BB07;
}
.activi1{
position: relative;
width: 750upx;
height: 84upx;
flex-direction: row;
}
/* 中部八个按钮 */
.box2 {
background-color: #FFFFFF;
padding-bottom: 20rpx;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
}
.box2-1 {
margin-top: 16rpx;
margin-left: 10rpx;
margin-right: 10rpx;
}
.box2-1-2 {
width: 160rpx;
justify-content: center;
align-items: center;
}
.box2-1-2-img {
height: 65rpx;
width: 65rpx;
margin-bottom: 20rpx;
/* border-radius: 85rpx; */
}
.box2-1-2-text {
font-size: 35rpx;
}
.box2-1-1 {
border-radius: 20rpx;
margin-left: 6rpx;
margin-right: 6rpx;
width: 140rpx;
height: 90rpx;
background-color: #f9f047;
justify-content: center;
align-items: center;
}
/* #ifndef APP-PLUS */
page {
width: 100%;
min-height: 100%;
display: flex;
}
/* #endif */
.page {
flex: 1;
}
.header {
flex-direction: row;
align-items: center;
justify-content: center;
margin-bottom: 5rpx;
}
/* 滑动区样式 */
.scroll{
flex-direction: row;
background-color: #FFFFFF;
}
.scroll-view{
margin-left: 10rpx;
margin-right: 10rpx;
}
.scroll-view-image{
width: 260rpx;
height: 150rpx;
border-radius: 20rpx;
}
.scroll-view-text{
text-align: center;
text-overflow: ellipsis;
line-height: 150rpx;
font-size: 32rpx;
position: absolute;
color: #FFFFFF;
background-color: rgba(0,0,0,0.5);
width: 260rpx;
border-radius: 20rpx;
}
/* 滑动区样式 end*/
.header-title {
font-size: 30px;
font-weight: bold;
color: #444;
}
.flexible-view {
background-color: #f823ff;
}
.page-head {
height: 200px;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: red;
}
.tabs {
flex-direction: column;
overflow: hidden;
background-color: #ffffff;
}
.tab-bar {
width: 750rpx;
padding-top: 10rpx;
padding-bottom: 10rpx;
flex-direction: row;
}
/* #ifndef APP-NVUE */
.tab-bar ::-webkit-scrollbar {
display: none;
width: 0 !important;
height: 0 !important;
-webkit-appearance: none;
background: transparent;
}
/* #endif */
.scroll-view-indicator {
position: relative;
height: 4px;
background-color: transparent;
}
.scroll-view-underline {
position: absolute;
top: 0;
bottom: 0;
width: 0;
border-radius: 10rpx;
background-color: #ffe411;
}
.scroll-view-animation {
transition-duration: 0.2s;
transition-property: left;
}
.tab-bar-line {
height: 1upx;
background-color: #cccccc;
}
.tab-view {
flex: 1;
}
.uni-tab-item {
flex-wrap: nowrap;
padding-left: 38rpx;
padding-right: 38rpx;
}
.uni-tab-item-title {
color: #AAAAAA;
font-size: 33rpx;
margin-bottom: 10rpx;
flex-wrap: nowrap;
}
.uni-tab-item-title-active {
color: #000000;
}
.swiper-item {
flex: 1;
flex-direction: column;
}
.swiper-page {
flex: 1;
flex-direction: row;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
</style>
Hi校园 (作者)
会,时不时会自动吸顶
2021-01-20 10:30
Hi校园 (作者)
我现在定义下来的情况就是list,切换到这个页面的时候,会多次自动滚动 监听他的滚动事件发现的。
2021-01-20 10:31
Hi校园 (作者)
应该是bug了
2021-01-20 10:31
DCloud_UNI_Anne
回复 Hi校园: 是必现吗?其他设备上是否也有此问题?
2021-01-20 13:01
Hi校园 (作者)
回复 DCloud_UNI_Anne: 苹果不会出现,安卓时不时出现且出现的频率很大
2021-01-20 16:33
Hi校园 (作者)
你看到我发的那个视频了吗?
2021-01-20 16:34
DCloud_UNI_Anne
回复 Hi校园: 问题排查中,已加分,感谢您的反馈!
2021-01-22 17:12
Hi校园 (作者)
回复 DCloud_UNI_Anne: 怎么样了 太着急了
2021-02-04 13:48