前端页面左右布局,点击左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>
相关推荐
之歆8 分钟前
Promise 基础技术深度解析:从回调地狱到链式调用
前端·okhttp·promise
甲维斯10 分钟前
国产版“Codex”初体验,智谱ZCode很强啊!
前端·人工智能·ai编程
道友可好12 分钟前
AI 怎么自己跑完一个 6 小时的任务?
前端·人工智能·后端
To_OC25 分钟前
通义千问多模态生图踩坑记:我是如何把两个报错逐个干翻的
前端·aigc·vite
Bigfish_coding29 分钟前
前端转agent-第一周【python】-02 FastAPI与Pydantic实战(TS/JS视角)
前端
秃头网友小李30 分钟前
前端难点:Vue3 响应式遇上 Three.js / ECharts —— 为什么要用 shallowRef?
前端·vue.js
梦曦i32 分钟前
Vite插件开发框架:14个实用插件与完整工具包
前端
KaMeidebaby33 分钟前
卡梅德生物技术快报|biotin 生物素标记抗体全流程
前端·人工智能·算法·数据挖掘·数据分析
VitoChang33 分钟前
前端也能快速入门后端! NestJS前台和后台的Auth认证
前端·后端
TheITSea34 分钟前
一、React初体验:搭建、解析现代开发环境
前端·react.js·前端框架