当前位置: 首页 > news >正文

uni-app项目实战笔记14--给全屏页面添加遮罩层

接着上一篇,给全屏页面加上遮罩层,先来看效果:

从图片上看,遮罩分上下两层:

1.上层显示计数,时间和日期;

2.下层显示信息,评分和下载。

模板层代码:

<template><view class="preview"><swiper circular><swiper-item  v-for="item in 5"><image @click="maskChange" src="/common/images/preview1.jpg" mode="aspectFill"></image></swiper-item></swiper><view class="mask" v-if="maskState"><view class="goBack"></view><view class="count">3 / 9</view><view class="time"><uni-dateformat :date="new Date()" format="hh:mm"></uni-dateformat></view><view class="date"><uni-dateformat :date="new Date()" format="MM月dd日"></uni-dateformat></view><view class="footer"><view class="box"><uni-icons type="info" size="28"></uni-icons><view class="text">信息</view></view><view class="box"><uni-icons type="star" size="28"></uni-icons><view class="text">5分</view></view><view class="box"><uni-icons type="download" size="23"></uni-icons><view class="text">下载</view></view></view></view></view>
</template>

知识要点:

1.引入uniapp时间格式化组件,对时间和日期进行格式化显示:‘

<view class="time"><uni-dateformat :date="new Date()" format="hh:mm"></uni-dateformat>
</view>
<view class="date"><uni-dateformat :date="new Date()" format="MM月dd日"></uni-dateformat>
</view>

2.定义maskChange点击事件控制遮罩层的显示与隐藏。

<script setup>import {ref} from "vue"const maskState = ref(true)function maskChange(){maskState.value = !maskState.value}
</script>

CSS代码

<style lang="scss" scoped>.preview{width: 100%;height: 100vh;position: relative;swiper{width: 100%;height: 100%;image{width: 100%;height: 100%;}}.mask{&>view{position: absolute;left: 0;margin: auto;right: 0;color: #fff;width: fit-content;}.goBack{}.count{top:10vh;background: rgba(0,0,0,0.3);font-size: 28rpx;border-radius: 40rpx;padding: 8rpx 28rpx;backdrop-filter: blur(10rpx);}.time{font-size: 140rpx;top:calc(10vh + 80rpx);font-weight: 100;line-height: 1em;text-shadow: 0 4rpx rgba(0,0,0,0.3);}.date{font-size: 34rpx;top:calc(10vh + 230rpx);text-shadow: 0 2rpx rgba(0,0,0,0.3);}.footer{background: rgba(255,255,255,0.8);bottom:10vh;width: 65vw;height: 120rpx;border-radius: 120rpx;color:#000;display: flex;justify-content: space-around;align-items: center;box-shadow: 0 2rpx 0 rgba(0, 0, 0, 0.1);backdrop-filter: blur(20rpx);.box{display: flex;flex-direction: column;align-items: center;justify-content: center;padding: 2rpx 12rpx;.text{font-size: 20rpx;color: $text-font-color-2;}}}}}     
</style>

知识要点:

1. 遮罩层通用样式
.mask > view {position: absolute;left: 0;right: 0;margin: auto;  // 水平居中width: fit-content; // 宽度适应内容color: #fff;  // 默认白色文字
}
  • 作用:所有mask的直接子 view 元素(.goBack.count.time.date.footer)共用绝对定位和居中逻辑,使用.mask > view{}来声明通用样式

  • 例外.footer 单独覆盖了部分样式(如颜色、定位)。

2. 顶部计数指示器 (.count)
.count {top: 10vh;  // 距顶部10%视口高度background: rgba(0,0,0,0.3); // 半透明黑底border-radius: 40rpx;  // 胶囊形状backdrop-filter: blur(10rpx); // 磨砂效果}
3. 时间与日期 (.time & .date)
.time {font-size: 140rpx;  // 超大字号top: calc(10vh + 80rpx); // 位于计数下方font-weight: 100;   // 细体字text-shadow: 0 4rpx rgba(0,0,0,0.3); // 文字投影
}.date {font-size: 34rpx;top: calc(10vh + 230rpx); // 时间下方text-shadow: 0 2rpx rgba(0,0,0,0.3);
}
4. 底部操作栏 (.footer)
.footer {bottom: 10vh;  // 距底部10%视口高度width: 65vw;   // 宽度65%视口height: 120rpx;background: rgba(255,255,255,0.8); // 半透明白底border-radius: 120rpx; // 圆形backdrop-filter: blur(20rpx); // 强模糊.box {// 每个操作项垂直居中排列图标和文字}
}

相关文章:

  • 【整数递增加法拆分】2022-4-11
  • adoc(asciidoc)转为markdown的方法,把.adoc文件转换为markdown格式
  • CentOS7报错:Cannot find a valid baseurl for repo: base/7/x86_64
  • Burgers方程初值问题解的有效区域
  • shell三剑客
  • 《开窍》读书笔记8
  • LangGraph基础知识( Multi-agent)(六)
  • 【医疗电子技术-7.2】血糖监测技术
  • 【构建】CMake 构建系统重点内容
  • volatile 对 int 和 long 修改的区别
  • 傅里叶级数从三角函数形式到复指数形式的完整推导步骤
  • Chapter10-XXE
  • C++ 内存泄露
  • 【机械视觉】Halcon—【十三、实例找各个区域面积和中心点】
  • Bambu Studio 中的“回抽“与“装填回抽“的区别
  • 数据赋能(256)——数据赋能业务——产品和服务变现
  • 山东大学软件学院创新项目实训开发日志——第十六周
  • sd调试记录(标准库 + keil + RL-FlashFS):
  • 芯片测试之 trim修调详解
  • 人工智能嵌入公共服务治理的风险挑战(三)
  • 网站建设方案下载/最近的电脑培训班在哪里
  • 个体营业执照网上申请/太原seo报价
  • 12380网站建设意见/舟山百度seo
  • 佛山做推广网站的/教育培训机构营销方案
  • 简单网站的设计与制作/优化网站的方法有哪些
  • 关于党风廉政建设的网站/河南网站优化公司