前端页面左右布局,点击左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>
相关推荐
爱泡脚的鸡腿20 分钟前
uni-app D3实战(小兔仙)
前端
嬉皮客31 分钟前
Gird布局详解
前端·css
烛阴31 分钟前
C#常量(const)与枚举(enum)使用指南
前端·c#
Wect34 分钟前
学习React-DnD:实现多任务项拖拽-useDrag处理
前端
mucheni42 分钟前
迅为RK3568开发板OpeHarmony学习开发手册-修改应用程序名称
linux·前端·学习
WebGirl44 分钟前
SSE服务
前端
Mintopia1 小时前
🛰️ 低带宽环境下的 AIGC 内容传输优化技术
前端·人工智能·trae
h***34631 小时前
Nginx 缓存清理
android·前端·后端
Mintopia1 小时前
⚡Trae Solo Coding 的效率法则
前端·人工智能·trae
wa的一声哭了1 小时前
WeBASE管理平台部署-WeBASE-Web
linux·前端·网络·arm开发·spring boot·架构·区块链