前端页面左右布局,点击左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>
相关推荐
风骏时光牛马2 小时前
用户管理模块接口开发
前端
彭亚川Allen3 小时前
从零手搓 RAG 之检索全流程,给大模型接上自己的知识库
前端·后端·ai编程
IT_陈寒3 小时前
别让Java字符串拼接偷偷吃掉你的内存
前端·人工智能·后端
软件技术NINI3 小时前
圣罗兰彩妆html+css 4页
前端·css·html
2601_951615204 小时前
网站模板 网站网页模板下载
前端·网络·html
酷炫码神4 小时前
Day 1|HTML5:一个商城首页的骨架,从 DOCTYPE 到语义化
前端·html·html5
AI源码5 小时前
鲜花商城(HTML 版)
前端·html
hiahiahia1235 小时前
Message 和对话
服务器·前端·数据库
溪语流沙5 小时前
【Web全栈进阶】Composition API与组件通信:props深入、emit、插槽
前端·css·vue.js
ZoeLandia5 小时前
TypeScript 03:泛型与工具类型
前端·typescript