uniapp小案例---趣味打字坤

当点击输入框时出现小鸡打字

当输入框失焦时打字鸡沉下去

原图自取

这里运用了一个三元 :class="isActive?'active':''",当聚焦时isActive=true从而让class绑定,当失焦时isActive=false

复制代码
<template>
  <view class="out">
    <input type="text" @focus="isActive=true" @blur="isActive=false" placeholder="请输入用户名" />
    <image class="pic" :class="isActive?'active':''"  src="../../static/test/630ef32c0688d0bc83977e0344dda16c.gif"></image>

  </view>
</template>

<script setup>
  import {ref} from "vue";
  const isActive=ref(false);


</script>

<style lang="scss" scoped>
  .out{
    // background-color: darkgray;
    width: 100%;
    height: 100px;
    padding-top: 10px;
    input{
      background-color: #fff;
      margin-top: 20px;
      margin-left: 18px;
      width: 380px;
      height: 40px;
      border: 1px solid black;
      position: relative;
      z-index: 2;
    }
    .pic{
      width: 30px;
      height: 30px;
      // 相对于最近的定位祖先元素定位:
      position: absolute;
      top: 30px;
      // 混合单位运算
      left: calc(50% - 12px);
      z-index: 1;
      // 当top值发生变化时,平滑过度
      transition: top 0.3s;

    }
    .pic.active{
      top:5px;
    }
  }
</style>
相关推荐
lizhongxuan1 小时前
Claude Code 防上下文爆炸:源码级深度解析
前端·后端
天真萌泪2 小时前
JS逆向自用
开发语言·javascript·ecmascript
柳杉3 小时前
震惊!字符串还能这么玩!
前端·javascript
是上好佳佳佳呀3 小时前
【前端(五)】CSS 知识梳理:浮动与定位
前端·css
仍然.3 小时前
算法题目---模拟
java·javascript·算法
wefly20174 小时前
纯前端架构深度解析:jsontop.cn,JSON 格式化与全栈开发效率平台
java·前端·python·架构·正则表达式·json·php
我命由我123455 小时前
React - 类组件 setState 的 2 种写法、LazyLoad、useState
前端·javascript·react.js·html·ecmascript·html5·js
聊聊MES那点事5 小时前
JavaScript图表控件AG Charts使用教程:使用AG Charts React实时更新柱状图
开发语言·javascript·react.js·图表控件
自由生长20246 小时前
IndexedDB的观察
前端
IT_陈寒6 小时前
Vite热更新坑了我三天,原来配置要这么写
前端·人工智能·后端