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>
相关推荐
摘星编程28 分钟前
OpenHarmony环境下React Native:自定义useTruncate文本截断
javascript·react native·react.js
Duang007_1 小时前
【LeetCodeHot100 超详细Agent启发版本】字母异位词分组 (Group Anagrams)
开发语言·javascript·人工智能·python
有来技术1 小时前
Spring Boot 4 + Vue3 企业级多租户 SaaS:从共享 Schema 架构到商业化套餐设计
java·vue.js·spring boot·后端
东东5162 小时前
学院个人信息管理系统 (springboot+vue)
vue.js·spring boot·后端·个人开发·毕设
2601_949868362 小时前
Flutter for OpenHarmony 电子合同签署App实战 - 主入口实现
开发语言·javascript·flutter
m0_748229992 小时前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
C澒3 小时前
前端监控系统的最佳实践
前端·安全·运维开发
xiaoxue..3 小时前
React 手写实现的 KeepAlive 组件
前端·javascript·react.js·面试
摘星编程3 小时前
在OpenHarmony上用React Native:自定义useHighlight关键词高亮
javascript·react native·react.js
hhy_smile3 小时前
Class in Python
java·前端·python