欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解微信小程序scroll-view橫向滾動(dòng)的實(shí)踐踩坑及隱藏其滾動(dòng)條的實(shí)現(xiàn)

 更新時(shí)間:2019年03月14日 14:56:01   作者:ever  
這篇文章主要介紹了詳解微信小程序scroll-view橫向滾動(dòng)的實(shí)踐踩坑及隱藏其滾動(dòng)條的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

一、實(shí)踐踩坑

項(xiàng)目使用mpvue開發(fā)

1. scroll-view默認(rèn)是不滾動(dòng)的。。所以要先設(shè)置scroll-x="true"或者scroll-y="true"

2. 在scroll-view里面添加定寬元素,超過scroll-view寬度(設(shè)置了100%,即屏幕寬度)后,它竟然換行了。所以要scroll-view的樣式要這樣設(shè)置:

 scroll-view {
   width: 100%;
   white-space: nowrap; // 不讓它換行
  }

3. 然后在定寬元素里邊添加子容器:

// html大概長這樣
<scroll-view scroll-x="true">
 <div class="tab-item">
  <img class="content-icon"/>
  <div></div>
 </div>
 <div class="tab-item">
  <img class="content-icon"/>
  <div></div>
 </div>
 <div class="tab-item">
  <img class="content-icon"/>
  <div></div>
 </div>
</scroll-view>

// css相應(yīng)就大概長這樣
scroll-view {
  display: flex;
  flex-wrap: nowrap;
}
.tab-item {
  display: flex;
  justify-content: center;
  width: 25%;
  ...
}

然后發(fā)現(xiàn).tab-item并沒有排在一行上。。說明scroll-view.tab-item都設(shè)置display: flex無效?無奈之下,只好在它外邊再包一層,然后樣式設(shè)置display: inline-block。此時(shí)正確姿勢(shì)如下:

// html
<div class="scroll-view-container">
 <scroll-view scroll-x="true" :scroll-into-view="toView">
  <div class="tab-container">
   <div class="tab-item">
    <img class="content-icon"/>
    <div></div>
   </div>
  </div>
 </scroll-view>
</div>

// css變成這樣子
scroll-view {
 width: 100%;
 white-space: nowrap; // 不讓它換行
}

.tab-container {
 display: inline-block;
 width: 25%;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  ...
}

到這里,scroll-view就基本如我所愿了,大概長這樣:

二、隱藏滾動(dòng)條

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

/*隱藏滾動(dòng)條*/

::-webkit-scrollbar{

  width: 0;
  
  height: 0;
  
  color: transparent;

}

或者有的人說這樣子:

/*隱藏滾動(dòng)條*/

::-webkit-scrollbar{

  display: none;

}

然而兩種方法我都試過,scroll-view的滾動(dòng)條依然存在。。測(cè)試機(jī)型是安卓機(jī)子。

但是用display: none這種方法是可以隱藏掉頁面的滾動(dòng)條的,就是scroll-view的滾動(dòng)條沒隱藏掉。

后來,在小程序社區(qū)看到官方人員這樣子解答:

是的,就是這種野路子。當(dāng)然 ,它下面的評(píng)論里也有人提供了另一種解決思路方法,但我還是選擇了官方說的那種野路子方法。傳送門

實(shí)現(xiàn)思路就是,在scroll-view外邊再包一個(gè)容器,它的高度小于scroll-view的高度,這樣就會(huì)截掉滾動(dòng)條,達(dá)到隱藏了滾動(dòng)條的效果。

// scss
.scroll-view-container { // 包裹scroll-view的容器
  height: $fakeScrollHeight;
  overflow: hidden; // 這個(gè)設(shè)置了就能截掉滾動(dòng)條啦
  scroll-view {
   width: 100%;
   white-space: nowrap;
  }
 }

 .tab-container { // 我這里是用.tab-container來撐開scroll-view的高度,所以高度在它上面設(shè)置,加上padding,那么它就會(huì)比外層容器(.scroll-view-container)要高
  display: inline-block;
  width: 26%;
  height: $fakeScrollHeight;
  padding-bottom: $scrollBarHeight;
 }

大概意思是這樣:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論