前端页面左右布局,点击左div增加动画过渡效果

效果图如下

以下代码基于Vue2

javascript 复制代码
<template>
  <div class="container">
    <div class="left-section" :style="{ width: widthLeft + 'vw' }" @click="toggleRightSection"></div>
    <div class="right-section" :style="{ width: (100 - widthLeft) + 'vw' }"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      widthLeft: 60  // 左侧初始宽度
    };
  },
  methods: {
    toggleRightSection() {
      // 切换宽度
      if (this.widthLeft === 60) {
        this.widthLeft = 100;  // 隐藏右侧盒子
      } else {
        this.widthLeft = 60;  // 显示右侧盒子
      }
    }
  }
};
</script>

<style>
.container {
  display: flex;
  height: 80vh;
  overflow: hidden;
}

.left-section {
  transition: width 0.3s ease-in-out;
  background-color: #e0e0e0;
  padding: 20px;
}

.right-section {
  transition: width 0.3s ease-in-out;
  background-color: #c0c0c0;
  /* padding: 20px; */
}
</style>
相关推荐
知识分享小能手23 分钟前
Vue3 学习教程,从入门到精通,Axios 在 Vue 3 中的使用指南(37)
前端·javascript·vue.js·学习·typescript·vue·vue3
程序员码歌3 小时前
【零代码AI编程实战】AI灯塔导航-总结篇
android·前端·后端
用户21411832636024 小时前
免费玩转 AI 编程!Claude Code Router + Qwen3-Code 实战教程
前端
小小愿望5 小时前
前端无法获取响应头(如 Content-Disposition)的原因与解决方案
前端·后端
小小愿望5 小时前
项目启功需要添加SKIP_PREFLIGHT_CHECK=true该怎么办?
前端
烛阴5 小时前
精简之道:TypeScript 参数属性 (Parameter Properties) 详解
前端·javascript·typescript
海上彼尚6 小时前
使用 npm-run-all2 简化你的 npm 脚本工作流
前端·npm·node.js
开发者小天6 小时前
为什么 /deep/ 现在不推荐使用?
前端·javascript·node.js
如白驹过隙7 小时前
cloudflare缓存配置
前端·缓存
excel7 小时前
JavaScript 异步编程全解析:Promise、Async/Await 与进阶技巧
前端