微信小程序弹框之cover-view

微信小程序弹框之cover-view
1: 最近商户端小程序有个需求涉及到textarea,在textarea上方会有个弹框的交互效果,因为textarea是原生组件,层级比较高,一般的设置view的z-index是没有效果的,会造成如下的情况 (会导致点击textarea的时候,依旧可以点击):
微信小程序弹框之cover-view_第1张图片
1.jpeg
微信小程序弹框之cover-view_第2张图片
2.jpeg
2: 如果想在页面上,设置更高层级的视图且保证不被textarea覆盖,那么就需要使用cover-view了。由于项目需求是点击提价预约按钮,显示弹窗提示,预期效果如下:
微信小程序弹框之cover-view_第3张图片
3.jpeg
3: cover-view简述
cover-view 在小程序中是比较特殊的组件,与 view 的最大区别在于,它能覆盖在原生组件 map、video、canvas、camera、textarea 之上,且只能嵌套 cover-view 和 cover-image, 如果项目有这张需求,cover-view是一种行之有效的解决方法.
4: 针对上面的描述, 具体的代码如下

(1) wxml代码如下



(2) wxss代码如下:

.pop-up-textarea-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

.pop-up-textarea-container {
  position: fixed;
  top: 300rpx;
  left: 85rpx;
  width: 580rpx;
  height: 560rpx;
  background-color: #fff;
  border-radius: 8rpx;
  color: #666;
  font-size: 28rpx;
}

.top-view {
  height: 98rpx;
  width: 100%;
  display: flex;
  position: relative;
  align-items: center;
  justify-content: center;
  background-color: #fff;
}

.top-view .title {
  height: 98rpx;
  line-height: 98rpx;
  width: 100%;
  font-size: 36rpx;
  text-align: center;
}

.top-view .cancel {
  position: absolute;
  width: 60rpx;
  height: 60rpx;
  right: 20rpx;
  top:50%;
  transform: translateY(-50%);
}

.line-view, .top-line-view {
  width: 100%;
  height: 2rpx;
  background-color: #eeeeee
}

.top-line-view {
  background-color: #39cc6a
}

.pay-money-title {
  width: 100%;
  height: 98rpx;
  line-height: 98rpx;
  color: #333333;
  font-size: 32;
  text-align: center;
}

.pay-money-view {
  height: 60rpx;
  margin: 36rpx 30rpx 20rpx;
  justify-content: center;
  display: flex;
}

.pay-money-view .symbol {
  width: 33%;
  height: 40rpx;
  line-height: 40rpx;
  margin-top: 20rpx;
  font-size: 30rpx;
  text-align: right;
}

.pay-money-view .price {
  width: 67%;
  height: 60rpx;
  line-height: 60rpx;
  margin-left: 10rpx;
  color: #000;
  font-size: 60rpx;
  text-align: left;
}

.pet-card-view {
  height: 86rpx;
  margin-left: 30rpx;
  margin-right: 30rpx;
  align-items: center;
  display: flex;
}

.pet-card-view .icon{
  width:46rpx;
  height:46rpx;
  border-radius:23rpx
}

.pet-card-view .title{
  width: 200rpx;
  height: 46rpx;
  line-height: 46rpx;
  margin: 20rpx;
  color: #6E726E;
  text-align: left;
}

.bottom-make-sure-button {
  height: 92rpx;
  line-height: 92rpx;
  margin: 40rpx 30rpx 20rpx;
  background-color: #06C160;
  border-radius: 8rpx;
  color: #fff;
  justify-content: center;
  align-items: center;
  text-align: center;
}

你可能感兴趣的:(微信小程序弹框之cover-view)