【前端】50个项目HiddenSearchWidget#4

作者参与了GitHub上的50Projects50Days挑战,计划使用Vue2和Vue3分别重构15个和30个项目,以此来提升技能并巩固基础知识。文章详细介绍了使用Vue2实现HiddenSearchWidget的过程,包括模板、脚本和样式部分,以及应用的动画效果和交互功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

才发现github上有个50projects50days的项目,感觉还挺有趣的,可以练手学习,增加点代码练习,巩固下基础知识。
计划用vue2改写15个项目,vue3+js改写15个项目,vue3+ts改写20个项目。
在此仅作个人记录,权当打卡and水文章了hh

实现

第四个项目,HiddenSearchWidget,基于vue2实现
(简单的学习笔记在代码中)
在这里插入图片描述
在这里插入图片描述

<template>
  <div class="body">
    
    <div class="search" ref="search">
      <input type="text" class="input" ref="input" placeholder="Search...">
      
      <button class="btn" @click="click">
        <i class="fas fa-search"></i>
      </button>
    </div>

  </div>
</template>
<script>
export default {
  name: 'HiddenSearchWidget',
  components: {

  },
  data() {
    return {

    }
  },
  methods: {
    click(){
      this.$refs.search.classList.toggle('active')
      this.$refs.input.focus()
    }
  }

}

</script>
  
<style scoped>
@import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css");
.body {
  box-sizing: border-box!important;
  /* 线性渐变,渐变轴 */
  background-image: linear-gradient(90deg,#7d5fff, #7158e2);
  font-family: 'Roboto', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  height:100vh;
  overflow: hidden;
  margin: 0;
}

.search {
  
  position: relative;
  height: 50px;
}

.search .input {
  background-color: #fff;
  border: 0;
  font-size: 18px;
  padding: 15px;
  height: 50px;
  width: 50px;
  /* 触发动画时内容 */
  transition: width 0.3s ease;
}

.btn {
  background-color: #fff;
  border: 0;
  cursor: pointer;
  font-size: 24px;
  position: absolute;
  top:0;
  left:0;
  height: 50px;
  width: 50px;
  /* 触发动画时内容 */
  transition: transform 0.3s ease;
}

.btn:focus,
.input:focus {
  /* 取消聚焦时的外边框 */
  outline: none;
}

.search.active .input {
  /* 动画的结束状态 */
  width: 200px;
}

.search.active .btn{
  /* 动画的结束状态 */
  transform: translateX(198px);
}
</style>
  

其他

补充资料,配色可以查看:
配色知识-掘金
uigradients

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值