- 发布:2021-02-27 03:20
- 更新:2021-03-29 20:04
- 阅读:1087
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 10.15.8
HBuilderX类型: 正式
HBuilderX版本号: 3.1.2
手机系统: 全部
手机厂商: 苹果
页面类型: vue
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
示例代码:
<template>
<view class="content">
<scroll-view :scroll-x="true" style="white-space: nowrap;margin-left: 20rpx; width: 730rpx; height: 100rpx ; background-color: #0077AA; padding-top: 200rpx;"
:show-scrollbar="true" :scroll-into-view="scrollintoview" :scroll-with-animation="true" id="tabtop">
<view style="width: 145rpx; display: inline-block;" v-for="(item,index) in tabBars" :key="item.id" :id="'tab'+index"
:class="tabIndex === index ? 'selectText l-color-main' : '' " @click="changeTab(index)">{{item.title}}</view>
</scroll-view>
<swiper style="background-color: #007AFF; width: 750rpx; height: 490px;" @change="onChangeTab" :current="current">
<swiper-item v-for="(item,index) in tabBars" :key="item.id" >
<text>1</text>
</swiper-item>
</swiper>
<!-- <block v-for="item,index in list" :key="index">
<commenList :item="item" :index="index" @followed="followed" @doSupport="doSupport"></commenList>
<commonHorizontalLine></commonHorizontalLine>
</block> -->
</view>
</template>
<script>
import commenList from "@/component/common/common_list/common_list.vue"
import commonHorizontalLine from "@/component/common/common_horizontal_line/common_horizontal_line.vue"
export default {
components: {
commenList,
commonHorizontalLine
},
data() {
return {
tabIndex: 0,
current: 0,
scrollintoview: '',
tabBars: [{
id: 0,
title: "栏目0"
}, {
id: 1,
title: "栏目1"
}, {
id: 2,
title: "栏目2"
}, {
id: 3,
title: "栏目3"
}, {
id: 4,
title: "栏目4"
}, {
id: 5,
title: "栏目5"
}, {
id: 6,
title: "栏目6"
}, {
id: 7,
title: "栏目7"
}, {
id: 8,
title: "栏目8"
}, {
id: 9,
title: "栏目9"
}, {
id: 10,
title: "栏目10"
}],
list: [{
cname: "昵称1",
avatar: "/static/logo.png",
post_time: "2021年02月26日13:02:01",
is_follow: false,
title: "文章的标题",
title_pic: "/static/6acec660-4f31-11eb-a16f-5b3e54966275.jpg",
support: {
type: "support",
support_count: 1,
unsupport_count: 2
},
comment_count: 2,
share_count: 2
},
{
cname: "昵称2",
avatar: "/static/logo.png",
post_time: "2021年02月26日13:02:01",
is_follow: false,
title: "文章的标题",
title_pic: "/static/6acec660-4f31-11eb-a16f-5b3e54966275.jpg",
support: {
type: "unsupport",
support_count: 1,
unsupport_count: 2
},
comment_count: 2,
share_count: 2
},
{
cname: "昵称3",
avatar: "/static/logo.png",
post_time: "2021年02月26日13:02:01",
is_follow: false,
title: "文章的标题",
title_pic: null,
support: {
type: null,
support_count: null,
unsupport_count: 0
},
comment_count: null,
share_count: null
},
{
cname: "昵称3",
avatar: "/static/logo.png",
post_time: "2021年02月26日13:02:01",
is_follow: false,
title: "文章的标题",
title_pic: null,
support: {
type: "unsupport",
support_count: null,
unsupport_count: 0
},
comment_count: null,
share_count: null
}
]
}
},
onLoad() {
},
methods: {
changeTab(index) {
this.tabIndex = index,
this.scrollintoview = 'tab' + index
this.current = index
},
onChangeTab(e) {
this.tabIndex = e.detail.current
this.scrollintoview = 'tab' + e.detail.current
},
// 关注功能
followed(index) {
this.list[index].is_follow = true
uni.showToast({
title: "关注成功"
})
},
// 顶踩操作
doSupport(data) {
if (data.type == 'unsupport' && this.list[data.index].support.type != 'unsupport') {
this.list[data.index].support.unsupport_count = this.list[data.index].support.unsupport_count + 1
this.list[data.index].support.support_count = this.list[data.index].support.support_count - 1
if (this.list[data.index].support.support_count < 0) {
this.list[data.index].support.support_count = 0
}
uni.showToast({
title: "踩了一下"
})
}
if (data.type == 'support' && this.list[data.index].support.type != 'support') {
this.list[data.index].support.unsupport_count = this.list[data.index].support.unsupport_count - 1
this.list[data.index].support.support_count = this.list[data.index].support.support_count + 1
if (this.list[data.index].support.unsupport_count < 0) {
this.list[data.index].support.unsupport_count = 0
}
uni.showToast({
title: "顶了一下"
})
}
this.list[data.index].support.type = data.type;
}
},
onLoad() {
},
onReady() {
uni.getSystemInfo({
success: function(res) {
console.log(res.windowHeight);
}
});
const query = uni.createSelectorQuery().in(this);
query.select('#tabtop').boundingClientRect(data => {
console.log("得到布局位置信息" + JSON.stringify(data));
console.log("节点离页面顶部的距离为" + data.top);
}).exec();
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
/* 禁止IOS 横向划动出现滚动条 */
/deep/.uni-scroll-view::-webkit-scrollbar {
display: none;
}
.selectText {
font-weight: bold;
font-size: 42rpx;
}
</style>
<template>
<view class="content">
<scroll-view :scroll-x="true" style="white-space: nowrap;margin-left: 20rpx; width: 730rpx; height: 100rpx ; background-color: #0077AA; padding-top: 200rpx;"
:show-scrollbar="true" :scroll-into-view="scrollintoview" :scroll-with-animation="true" id="tabtop">
<view style="width: 145rpx; display: inline-block;" v-for="(item,index) in tabBars" :key="item.id" :id="'tab'+index"
:class="tabIndex === index ? 'selectText l-color-main' : '' " @click="changeTab(index)">{{item.title}}</view>
</scroll-view>
<swiper style="background-color: #007AFF; width: 750rpx; height: 490px;" @change="onChangeTab" :current="current">
<swiper-item v-for="(item,index) in tabBars" :key="item.id" >
<text>1</text>
</swiper-item>
</swiper>
<!-- <block v-for="item,index in list" :key="index">
<commenList :item="item" :index="index" @followed="followed" @doSupport="doSupport"></commenList>
<commonHorizontalLine></commonHorizontalLine>
</block> -->
</view>
</template>
<script>
import commenList from "@/component/common/common_list/common_list.vue"
import commonHorizontalLine from "@/component/common/common_horizontal_line/common_horizontal_line.vue"
export default {
components: {
commenList,
commonHorizontalLine
},
data() {
return {
tabIndex: 0,
current: 0,
scrollintoview: '',
tabBars: [{
id: 0,
title: "栏目0"
}, {
id: 1,
title: "栏目1"
}, {
id: 2,
title: "栏目2"
}, {
id: 3,
title: "栏目3"
}, {
id: 4,
title: "栏目4"
}, {
id: 5,
title: "栏目5"
}, {
id: 6,
title: "栏目6"
}, {
id: 7,
title: "栏目7"
}, {
id: 8,
title: "栏目8"
}, {
id: 9,
title: "栏目9"
}, {
id: 10,
title: "栏目10"
}],
list: [{
cname: "昵称1",
avatar: "/static/logo.png",
post_time: "2021年02月26日13:02:01",
is_follow: false,
title: "文章的标题",
title_pic: "/static/6acec660-4f31-11eb-a16f-5b3e54966275.jpg",
support: {
type: "support",
support_count: 1,
unsupport_count: 2
},
comment_count: 2,
share_count: 2
},
{
cname: "昵称2",
avatar: "/static/logo.png",
post_time: "2021年02月26日13:02:01",
is_follow: false,
title: "文章的标题",
title_pic: "/static/6acec660-4f31-11eb-a16f-5b3e54966275.jpg",
support: {
type: "unsupport",
support_count: 1,
unsupport_count: 2
},
comment_count: 2,
share_count: 2
},
{
cname: "昵称3",
avatar: "/static/logo.png",
post_time: "2021年02月26日13:02:01",
is_follow: false,
title: "文章的标题",
title_pic: null,
support: {
type: null,
support_count: null,
unsupport_count: 0
},
comment_count: null,
share_count: null
},
{
cname: "昵称3",
avatar: "/static/logo.png",
post_time: "2021年02月26日13:02:01",
is_follow: false,
title: "文章的标题",
title_pic: null,
support: {
type: "unsupport",
support_count: null,
unsupport_count: 0
},
comment_count: null,
share_count: null
}
]
}
},
onLoad() {
},
methods: {
changeTab(index) {
this.tabIndex = index,
this.scrollintoview = 'tab' + index
this.current = index
},
onChangeTab(e) {
this.tabIndex = e.detail.current
this.scrollintoview = 'tab' + e.detail.current
},
// 关注功能
followed(index) {
this.list[index].is_follow = true
uni.showToast({
title: "关注成功"
})
},
// 顶踩操作
doSupport(data) {
if (data.type == 'unsupport' && this.list[data.index].support.type != 'unsupport') {
this.list[data.index].support.unsupport_count = this.list[data.index].support.unsupport_count + 1
this.list[data.index].support.support_count = this.list[data.index].support.support_count - 1
if (this.list[data.index].support.support_count < 0) {
this.list[data.index].support.support_count = 0
}
uni.showToast({
title: "踩了一下"
})
}
if (data.type == 'support' && this.list[data.index].support.type != 'support') {
this.list[data.index].support.unsupport_count = this.list[data.index].support.unsupport_count - 1
this.list[data.index].support.support_count = this.list[data.index].support.support_count + 1
if (this.list[data.index].support.unsupport_count < 0) {
this.list[data.index].support.unsupport_count = 0
}
uni.showToast({
title: "顶了一下"
})
}
this.list[data.index].support.type = data.type;
}
},
onLoad() {
},
onReady() {
uni.getSystemInfo({
success: function(res) {
console.log(res.windowHeight);
}
});
const query = uni.createSelectorQuery().in(this);
query.select('#tabtop').boundingClientRect(data => {
console.log("得到布局位置信息" + JSON.stringify(data));
console.log("节点离页面顶部的距离为" + data.top);
}).exec();
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
/* 禁止IOS 横向划动出现滚动条 */
/deep/.uni-scroll-view::-webkit-scrollbar {
display: none;
}
.selectText {
font-weight: bold;
font-size: 42rpx;
}
</style>
操作步骤:
1.获取屏幕的安全高度
uni.getSystemInfo({
success: function(res) {
console.log(res.windowHeight);
}
});
});
2.获取第一个元素scroll-view的bottom
scroll-view元素的代码
<scroll-view :scroll-x="true" style="white-space: nowrap;margin-left: 20rpx; width: 730rpx; height: 100rpx ; background-color: #0077AA; padding-top: 200rpx;"
:show-scrollbar="true" :scroll-into-view="scrollintoview" :scroll-with-animation="true" id="tabtop">
<view style="width: 145rpx; display: inline-block;" v-for="(item,index) in tabBars" :key="item.id" :id="'tab'+index"
:class="tabIndex === index ? 'selectText l-color-main' : '' " @click="changeTab(index)">{{item.title}}</view>
</scroll-view>
3.获取scroll-view距离顶部的距离
const query = uni.createSelectorQuery().in(this);
query.select('#tabtop').boundingClientRect(data => {
console.log("得到布局位置信息" + JSON.stringify(data));
console.log("节点离页面顶部的距离为" + data.top);
}).exec();
4.通过console.log的输出 手工进行计算
<swiper style="background-color: #007AFF; width: 750rpx; height: 490px;" @change="onChangeTab" :current="current">
<swiper-item v-for="(item,index) in tabBars" :key="item.id" >
<text>1</text>
</swiper-item>
</swiper>
5.可以发现 是可以上下滚动 5个像素 其他的如 iPhone12 和 pro 是3个像素 下面2张图片 可以通过放到 PS等工具查看 差了5个像素 图在附件
1.获取屏幕的安全高度
uni.getSystemInfo({
success: function(res) {
console.log(res.windowHeight);
}
});
});
2.获取第一个元素scroll-view的bottom
scroll-view元素的代码
<scroll-view :scroll-x="true" style="white-space: nowrap;margin-left: 20rpx; width: 730rpx; height: 100rpx ; background-color: #0077AA; padding-top: 200rpx;"
:show-scrollbar="true" :scroll-into-view="scrollintoview" :scroll-with-animation="true" id="tabtop">
<view style="width: 145rpx; display: inline-block;" v-for="(item,index) in tabBars" :key="item.id" :id="'tab'+index"
:class="tabIndex === index ? 'selectText l-color-main' : '' " @click="changeTab(index)">{{item.title}}</view>
</scroll-view>
3.获取scroll-view距离顶部的距离
const query = uni.createSelectorQuery().in(this);
query.select('#tabtop').boundingClientRect(data => {
console.log("得到布局位置信息" + JSON.stringify(data));
console.log("节点离页面顶部的距离为" + data.top);
}).exec();
4.通过console.log的输出 手工进行计算
<swiper style="background-color: #007AFF; width: 750rpx; height: 490px;" @change="onChangeTab" :current="current">
<swiper-item v-for="(item,index) in tabBars" :key="item.id" >
<text>1</text>
</swiper-item>
</swiper>
5.可以发现 是可以上下滚动 5个像素 其他的如 iPhone12 和 pro 是3个像素 下面2张图片 可以通过放到 PS等工具查看 差了5个像素 图在附件
预期结果:
应该不能上下滚动
应该不能上下滚动
实际结果:
可以上下滚动
可以上下滚动
bug描述:
如:页面除 原生导航栏和原生底部导航 一共2个元素 第一个scroll-view 第二个 swiper 其中swiper高度为自动获取,如下
在媒体查询中获取到可使用窗口高度【windowHeight】A 后 ,再通过createSelectorQuery获取第一个元素的bottom B
那么A-B = C 应该是屏幕剩下的像素 ,而在测试后 把C给swiper后,发现可以上下滚动几个像素,并且出现了滚动条
安卓手机没发现问题【自己用的不是全面屏】,而发现有问题的手机都是iPhone系列X后的,也就是全面屏,不确定安卓的全面屏手机是否也存在这样的问题,在小屏幕的iPhone上发现没问题
联系:17310646585 Q857523518 可以远程提供演示