溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

小程序如何實現scroll-view安卓機隱藏橫向滾動條

發布時間:2021-07-10 18:19:16 來源:億速云 閱讀:318 作者:小新 欄目:web開發

這篇文章主要介紹了小程序如何實現scroll-view安卓機隱藏橫向滾動條,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

一、實踐踩坑

項目使用mpvue開發

1.使用flex布局

// html大概長這樣

<div class="worth-wraper">
 <scroll-view scroll-x="true" scroll-left="0">
 <div class="worth-list">
 <div class="worth-item-img">
 <img src="/static/images/index/brand1.png" alt="">
 </div>
 <div class="worth-item-img">
 <img src="/static/images/index/brand2.png" alt="">
 </div>
 <div class="worth-item-img">
 <img src="/static/images/index/brand3.png" alt="">
 </div>
 <div class="worth-item-img">
 <img src="/static/images/index/brand4.png" alt="">
 </div>
 </div>
 </scroll-view>
</div>
// css相應就大概長這樣
.worth-wraper{

margin-top: 60rpx;
height: 560rpx;
box-sizing: border-box;
display: flex;
width: 750rpx;
overflow: hidden;
font-size: 28rpx;
color: #7a7269;
line-height: 42rpx;
.worth-list{
 display: flex;
 margin-left: 30rpx;
 .worth-item-img{
   flex: 1;
   margin-right: 20rpx;
   width: 290rpx;
   height: 560rpx;
 }
 img{
  width: 290rpx;
  height: 560rpx;
 }
 .worth-item{
  padding: 0 35rpx 0 40rpx;
  flex: 1;
  box-sizing: border-box;
  background: url("../../../static/images/index/worth-bg1.png") no-repeat;
  background-size: 100% 100%;
  width: 290rpx;
  height: 560rpx;
  margin-right: 20rpx;
 }
}
}

ios沒有問題,樣式正常,然后到了安卓機上,卻出現了橫向滾動條.......然后各種找如何去除橫向滾動條的方法....

二、隱藏滾動條

在網上搜了很多,都是說加上這段代碼就可以:

/隱藏滾動條/

::-webkit-scrollbar{

width: 0;

height: 0;

color: transparent;
}

或者有的人說這樣子:

/隱藏滾動條/

::-webkit-scrollbar{

display: none;
}

然而兩種方法我都試過,然而在安卓機上并沒什么鳥用。

后來看到有人這么說:

1.scroll-view 中的需要滑動的元素不可以用 float 浮動;

2.scroll-view 中的包裹需要滑動的元素的大盒子用 display:flex; 是沒有作用的;

3.scroll-view 中的需要滑動的元素要用 dislay:inline-block; 進行元素的橫向編排;

4.包裹 scroll-view 的大盒子有明確的寬和加上樣式--> overflow:hidden;white-space:nowrap;

好像能行得通....不用flex,不用float

然后改寫css代碼

.worth-wraper{

 margin-top: 60rpx;
 width: 750rpx;
 height: 560rpx;
 overflow: hidden; 
 scroll-view{
  width: 100%;
  white-space: nowrap;
 }
 .worth-list{
  display: inline-block;
  margin-left: 30rpx;
  padding-bottom: 60rpx; //加個padding值,這樣高度大于scroll-view外面包裹的元素
  .worth-item-img{
   margin-right: 20rpx;
   width: 290rpx;
   height: 560rpx;
   display: inline-block;
  }
 }
}

到這里,scroll-view安卓機上橫向滾動條消失了,大概長這樣:

小程序如何實現scroll-view安卓機隱藏橫向滾動條

感謝你能夠認真閱讀完這篇文章,希望小編分享的“小程序如何實現scroll-view安卓機隱藏橫向滾動條”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女