uniapp使用scroll-view實現左右上下滑動功能
更新時間:2022年11月24日 15:08:39 作者:@Winner
最近在用uni-app開發(fā)小程序時,需要用scroll-view做出左右上下滑動效果,所以下面這篇文章主要給大家介紹了關于uniapp使用scroll-view實現左右上下滑動功能的相關資料,需要的朋友可以參考下
闡述
我們在項目中往往都能遇到實現左右滑動跟上下滑動的需求,不需要安裝 better-scroll uniapp 自帶的scroll-view 就可以實現了。
實現左右滑動
<view class="model_scrollx flex_row">
<scroll-view class="uni-swiper-tab" scroll-x :style="'height:'+scrollH+'px'">
<view class="scrollx_items">
<button class="guige1 guige-active">蘋果</button>
</view>
<view class="scrollx_items">
<button class="guige1 guige-active">菠蘿</button>
</view>
<view class="scrollx_items">
<button class="guige1 guige-active">香蕉</button>
</view>
</scroll-view>
</view>
<script>
export default {
name: "shopping",
data() {
return {
scrollH: 130, // 高度
}
},
}
</script>
<style>
/* 二級菜單設置左右滑動 */
.uni-swiper-tab{
white-space: nowrap;
}
.model_scrollx{
justify-content: space-between;
height: 45px;
/* background-color: #F1EFEF; */
align-items: center;
}
.scrollx_items{
text-align: center;
display: inline-block;
width: 210rpx;
box-sizing: border-box;
margin-left: 30rpx;
margin-top: 3px;
}
.scrollx_items:last-child{
margin-right: 30rpx;
}
.scrollx_items image{
width: 70rpx;
height: 66rpx;
}
.tgyx_title{
font-size: 28rpx;
color: #333333;
margin-top: 30rpx;
}
.tgyx_desc{
font-size: 24rpx;
margin-top: 10rpx;
}
</style>

實現上下滑動
<template>
<view>
<view class="uni-padding-wrap uni-common-mt">
<view>
<scroll-view class="scroll-view" scroll-y="true" :scroll-top="scrollTop" @scroll="scroll" @scrolltoupper="upper"
@scrolltolower="lower">
<view class="scroll-view-item top">注冊地址</view>
<view class="scroll-view-item center">注冊地址</view>
<view class="scroll-view-item bottom">注冊電話</view>
</scroll-view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
scroll(event) {
//距離每個邊界距離
console.log(event.detail)
},
//滾動到底部/右邊觸發(fā)
scrolltolower() {
console.log(123213213213);
},
// 滾動到頂部/左邊觸發(fā)
scrolltoupper() {
console.log(2232332);
}
}
}
</script>
<style>
.scroll-view {
white-space: nowrap;
height: 200px;
width: 100%;
}
.top {
height: 200px;
width: 100%;
background: red;
}
.center {
height: 200px;
width: 100%;
background: green;
}
.bottom {
height: 200px;
width: 100%;
background: blue;
}
</style>

去掉scroll-view的滾動條
不能單獨設置到style樣式里面,uniapp要設置到全局App.vue這個文件下面才可生效。
<style>
/* 去除scroll滾動條 */
::-webkit-scrollbar {
width: 0;
height: 0;
background-color: transparent;
}
</style>
總結
到此這篇關于uniapp使用scroll-view實現左右上下滑動功能的文章就介紹到這了,更多相關uniapp用scroll-view左右上下滑動內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

