CSS - 搜刮框小动效

[复制链接]
发表于 2026-1-28 15:39:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
  1. 点击搜索框动画变长,搜索框有内容不变,无内容失去焦点,变回原来模样。
  2. <div :class="type == true ? 's_r_z' : 's_r'" @click="onChange">
  3.      <div class="input_s"><input @blur="handleBlur" v-model="input" required placeholder="请输入关键词搜索" /></div>
  4.      <img src="../../../../assets/images/v_15.png" />
  5. </div>
  6. mounted() {
  7.         // 监听全局点击事件
  8.         window.addEventListener('click', this.handleClickOutside);
  9.     },
  10. beforeDestroy() {
  11.       // 组件销毁前移除监听事件
  12.      window.removeEventListener('click', this.handleClickOutside);
  13. },
  14. methods: {
  15. // 如果点击事件的目标不是打开的div也不是其子元素,则关闭div
  16.         handleClickOutside(event) {
  17.        if (!this.$el.contains(event.target) && this.type && this.input == '') {
  18.            this.type = false;
  19.        }
  20.            },
  21.            onChange() {
  22.        this.type = true
  23.     },
  24. }
  25. .s_r {
  26.         display: flex;
  27.         width: 62px;
  28.         height: 30px;
  29.         background: #E3F1FF;
  30.         border-radius: 20px;
  31.         cursor: pointer;
  32.         margin: 0px 0px 0px 30px;
  33.         margin-top: -7px;
  34.         transition: all 1s ease-in-out;
  35.         -webkit-transition: width 1s;
  36.         img {
  37.             width: 20px;
  38.             height: 20px;
  39.             position: relative;
  40.             left: 20px;
  41.             top: 5px;
  42.         }
  43.         input {
  44.             display: none;
  45.         }
  46.     }
  47.     .s_r_z {
  48.         display: flex;
  49.         justify-content: center;
  50.         align-items: center;
  51.         width: 240px;
  52.         height: 30px;
  53.         background: #E3F1FF;
  54.         border-radius: 20px;
  55.         border: 1px solid #258DEC;
  56.         animation: kx 0.5s;
  57.         margin: 0px 0px 0px 30px;
  58.         margin-top: -8px;
  59.         img {
  60.             width: 20px;
  61.             height: 20px;
  62.         }
  63.         input {
  64.             outline-style: none;
  65.             border: none;
  66.             background-color: #E3F1FF;
  67.             animation: zk 1s;
  68.         }
  69.     }
  70.     @keyframes kx {
  71.         0% {
  72.             width: 0px
  73.         }
  74.         100% {
  75.             width: 240px;
  76.         }
  77.     }
  78.     @keyframes zk {
  79.         0% {
  80.             width: 0px
  81.         }
  82.         100% {
  83.             width: 200px;
  84.         }
  85.     }
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表