欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > uniapp小案例---趣味打字坤

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

2025/6/21 17:19:43 来源:https://blog.csdn.net/qq_62859013/article/details/144643625  浏览:    关键词: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>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词