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

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>
相关推荐
Vuji1 小时前
Pi 插件解剖|git-checkpoint.ts:只用 53 行,让 fork 恢复代码状态
前端·agent
大家的林语冰1 小时前
✌️ 让 Rust 再次伟大,pnpm 12 抛弃 TypeScript,移植 Rust 原地起飞!
前端·javascript·node.js
XPoet2 小时前
AI 编程工程化:实战——从 0 到 1 搭建 AI 编程工作流
前端·后端·ai编程
-今昭-3 小时前
Logstash 管理
java·服务器·前端
名字还没想好☜3 小时前
React 用自定义 useDebounce Hook 治好搜索框频繁请求:防抖、竞态取消与卸载清理
前端·javascript·react.js·react·hooks
杉氧3 小时前
Flutter 跨平台多端适配与 Android/iOS 一键自动化打包发布
android·前端·flutter
障碍的枫子3 小时前
xss和CSRF的攻击和防御
前端·xss·csrf
用户921080262863 小时前
3. 给 Bubble 新增一个 Agent Variant
前端
抓不住时间的沙3 小时前
butterfly主题美化,打造属于自己的个性博客
java·开发语言·前端·javascript·node.js·github
kyriewen3 小时前
前端切图仔被 AI 新闻淹死的第 N 天,我用 TRAE Work 定时任务救了自己
前端·人工智能·trae