前端页面左右布局,点击左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>
相关推荐
Patrick_Wilson3 分钟前
最佳实践是有保质期的:从一次 CDN external 白屏事故说起
前端·性能优化·前端工程化
YHHLAI29 分钟前
[特殊字符] Agent 智能体开发实战 · 第一课:Tool Use —— 让大模型自动干活
前端·人工智能
nuIl36 分钟前
我把 5 个编码 Agent 塞进了一个 npm 包
前端·agent·claude
L-影40 分钟前
FastAPI 静态文件:Web 页面的“固定展柜”与“加速引擎”
前端·fastapi
陪我去看海43 分钟前
受够了 AI 写完代码留下一堆端口?我做了一个端口管理App!
前端·macos·vibecoding
Xuepoo44 分钟前
我抛弃了 DOM,但保留了无障碍访问
前端
李明卫杭州1 小时前
Vue2 vs Vue3 的 h 函数:渲染函数完整迁移指南
前端
星栈1 小时前
LiveView 的认证系统:从登录到权限,我一开始以为有 `current_user` 就算完事了
前端·前端框架·elixir
在因斯坦1 小时前
摸摸鱼之前端自己研究 Jenkins 自动化部署
前端
snpgroupcn1 小时前
SAP实施风险管控注意事项:四大风险域与防范策略
前端·数据库·人工智能