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

javascript 复制代码
<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>
相关推荐
成都渲染101云渲染66662 小时前
如何在3ds Max中实现更快、更高质量的渲染
前端·javascript·人工智能
闲猫4 小时前
Spring AI 对接Deepseek ChatModel 聊天对话
java·前端·spring
自信的未来5 小时前
JSON 工具|Web Worker 工程化打包 + 语法自动修复 + 多语言代码生成实战
java·前端·json
SRET6 小时前
Mineradio 沙盒隔离安装完全指南 | 一键安全运行 Electron 应用!!!
javascript·经验分享·安全·electron·aigc·音视频·ai编程
全栈前端老曹6 小时前
【MongoDB】安全与权限管理 —— 用户认证、角色权限、SSL 加密
前端·javascript·数据库·安全·mongodb·nosql·ssl
zhangxingchao7 小时前
AI大模型核心八:从 Agent Skill、长文档 RAG 到知识库更新与训练策略
前端·人工智能·后端
zhangxingchao7 小时前
AI大模型核心七:从 Workflow、RAG、记忆治理到幂等性
前端·人工智能·后端
gyx_这个杀手不太冷静8 小时前
Agent开发进阶指南(第 1 章):AI Agent 到底是什么?
前端·agent·ai编程
小小小小宇8 小时前
模型相关知识
前端
小小小小宇8 小时前
模型相关知识二
前端