小程序圖片文字水平垂直居中對齊解決方案 以及 彈框出現禁止滾動

我們知道常用的居中對齊方式有很多種例如:

text-align:center;
align-items:center;
justify-content: center;
margin: auto;  #子容器在父容器中居中

但是在view中的文字對齊卻不能簡單的使用text-align: center;來實現,這種辦法只能實現文字的水平居中,

要實現水平垂直居中

可使用如下方案 給父元素添加以下代碼即可

.td {
  display: flex;
  align-items: center;
  justify-content: center;
}

使用了flex佈局控制其中的文字水平和垂直居中

彈框出現禁止滾動:
彈出 fixed 彈窗後,在彈窗上滑動會導致下層的頁面一起跟着滾動。
解決方法:

在彈出層加上 catchtouchmove 事件

示例代碼:

<view class="modal-view" hidden="{{!showModal}}" bindtap="toggleModal" catchtouchmove="preventTouchMove">
  <view class="modal">
  <view class="modal-item" catchtap="makePhoneCall">{{site.phone}}</view>
  <view class="modal-item" catchtap="toggleModal">取消</view>
  </view>
</view>

Pages({
preventTouchMove() {}
})
在電腦上測試是沒有用的,這是觸摸事件。因此,需要在手機端測試,預覽生成一個開發版,用手機微信掃描即可看到效果。

還有一種方法如下:給catchtouchmove=“ture”

<view class="modal-view" hidden="{{!showModal}}" bindtap="toggleModal" catchtouchmove="ture">
  <view class="modal">
  <view class="modal-item" catchtap="makePhoneCall">{{site.phone}}</view>
  <view class="modal-item" catchtap="toggleModal">取消</view>
  </view>
</view>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章