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

小程序的右侧抽屉开关动画手写效果

<template><view><button @click="openDrawer">打开抽屉</button><view v-if="showDrawer" class="drawer" :style="{ backgroundColor: bgColor }" @click="closeDrawer"><view class="drawerContent" :animation="animationData" @click.stop><view class="drawerName"><view style="font-weight: bold;" class="drawerName_title">价格区间(元)</view><view style="position: relative;"><text @click="closeDrawer" class="drawerName_icon qh-rt-single qh-rt-a-zu4416 choose-sku-close-icon"></text></view></view><!-- ... 其余内容保持不变 ... --></view></view></view>
</template><script>
export default {data() {return {showDrawer: false,animationData: {},bgColor: 'rgba(0, 0, 0, 0)',animation: null,// ... 其他数据}},methods: {openDrawer() {this.showDrawer = true;this.bgColor = 'rgba(0, 0, 0, 0)';this.$nextTick(() => {this.animation = uni.createAnimation({duration: 300,timingFunction: 'ease-out',});this.animation.translateX(0).step();this.animationData = this.animation.export();// 背景颜色渐变let opacity = 0;const bgInterval = setInterval(() => {opacity += 0.1;this.bgColor = `rgba(0, 0, 0, ${opacity})`;if (opacity >= 0.5) {clearInterval(bgInterval);}}, 30);});},closeDrawer() {this.animation.translateX('100%').step();this.animationData = this.animation.export();// 背景颜色渐变let opacity = 0.5;const bgInterval = setInterval(() => {opacity -= 0.1;this.bgColor = `rgba(0, 0, 0, ${opacity})`;if (opacity <= 0) {clearInterval(bgInterval);this.showDrawer = false;}}, 30);}}
}
</script><style lang="scss">
.drawer {position: fixed;top: 0;left: 0;width: 100%;height: 100%;display: flex;justify-content: flex-end;z-index: 999;
}.drawerContent {display: flex;flex-direction: column;justify-content: space-between;height: 100%;padding-top: 140rpx;background: #fff;width: 512rpx;transform: translateX(100%); // 初始位置在屏幕右侧
}// ... 其他样式保持不变 ...
</style>

http://www.lryc.cn/news/436279.html

相关文章:

  • vue3中el-table中点击图片放大时,被表格覆盖
  • GO学习笔记(4) strconv/time
  • 课程管理系统-数据库-基于MySQL的数据库课程设计
  • 降维打击 华为赢麻了
  • [数据集][目标检测]汽车头部尾部检测数据集VOC+YOLO格式5319张3类别
  • python 生成的代码,需要帮我生成一个直接在一台没有依赖的电脑上运行的 包
  • 【Linux】操作系统与进程
  • 【Linux】 LTG:移动硬盘部署Ubuntu24.04
  • Android的logcat日志详解
  • 【Linux】:信号的保存和信号处理
  • 深入理解Java虚拟机:Jvm总结-Java内存区域与内存溢出异常
  • 跨境电商必备保护账号的4个网络环境设置
  • Python+requests接口自动化测试框架实例教程
  • 【网络安全】DNS重绑定原理详析
  • C语言初识编译和链接
  • TrinityCore环境搭建
  • Proteus 仿真设计:开启电子工程创新之门
  • microchip dspic3一些奇怪问题
  • FinOps原则:云计算成本管理的关键
  • JavaScript之如何优化模板字符串的性能
  • 不能将类型“null”分配给类型“number | undefined”。ts(2322)
  • Nginx部署前端Vue项目详细教程
  • kvm 虚拟机命令行虚拟机操作、制作快照和恢复快照以及工作常用总结
  • 内网安全-横向移动【3】
  • 语言中的浮点数
  • Pyspark下操作dataframe方法(1)
  • 注解实现json序列化的时候自动进行数据脱敏
  • 使用Python下载文件的简易指南
  • 中秋国庆双节长假,景区迎来客流高峰,如何保障景区安全管理?
  • 多维数组转一维数组:探索 JavaScript 中的数组扁平化