css过渡动画--搜索

可应用于小程序,app的一种搜索样式之一,此示例利用css的transition属性,通过改变class类的方法实现

直接上代码

<template>
  <div class="header">
    <div class="head" :class="{ head2: changeCssStatus }">
      <div class="list">
        <span>列表一</span>
        <span>列表二</span>
      </div>
      <div class="text" @click="changebig">搜索</div>
    </div>

    <div class="search" :class="{ search2: changeCssStatus }">
      <div class="css1">搜索</div>
      <div style="text-align:center;flex:1;" @click="changeCssStatus=false">取消</div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
const changebig = () => {
  changeCssStatus.value = true
}
const changeCssStatus = ref<boolean>(false)
</script>

<style lang="scss" scoped>
.text {
  width: 50px;
  text-align: center;
  background: #666;
  color: white;
}
.css1 {
  width: 150px;
  background: #666;
}
.head {
  width: 100%;
  display: flex;
  transition: width 0.3s ease-out;
  overflow: hidden;
}
.head2 {
  width: 0;
  overflow: hidden;
}
.header {
  margin: 0 auto;
  width: 230px;
  padding: 5px 10px;
  box-sizing: border-box;
  display: flex;
  height: 30px;
  overflow: hidden;
  border-bottom: 1px solid red;
  .list {
    display: flex;
    width: 180px;
    text-align: center;
    span {
      width: 50%;
    }
  }
  .search {
    width: 0;
    overflow: hidden;
    display: flex;
  }
  .search2 {
    width: 100%;
    overflow: hidden;
    transition: width 0.3s ease-in-out;
  }
}
</style>

我使用的是vue3,但和vue2差不多呢

补上效果:

f13eb3c1bb81e6f3894407e5826493

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值