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>
相关推荐
科杰智能制造1 分钟前
纯前端html、js实现人脸检测和表情检测,可直接在浏览器使用
前端·javascript·html
每天吃饭的羊18 分钟前
组件库的有些点击事件是name-click这是如何分装de
前端·javascript·vue.js
Coder-coco18 分钟前
个人健康管理|基于springboot+vue+个人健康管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·mysql·论文
x***010629 分钟前
SpringSecurity+jwt实现权限认证功能
android·前端·后端
1024肥宅37 分钟前
防抖(Debounce)
前端·javascript·ecmascript 6
1024肥宅38 分钟前
节流(Throttle)
前端·javascript·ecmascript 6
大怪v41 分钟前
【Virtual World 02】两点一线!!!
javascript·css·html
by__csdn42 分钟前
Vue2纯前端图形验证码实现详解+源码
前端·javascript·typescript·vue·状态模式·css3·canva可画
Gomiko1 小时前
JavaScript基础(八):函数
开发语言·javascript·ecmascript
w***37511 小时前
Spring 核心技术解析【纯干货版】- Ⅶ:Spring 切面编程模块 Spring-Instrument 模块精讲
前端·数据库·spring