用uniapp写一个input输入动画
时间: 2023-05-17 11:04:38 浏览: 277
可以使用uniapp提供的transition组件来实现input输入动画。首先,在template中添加一个input组件,并为其添加一个class名,如下所示:
<template>
<div class="input-container">
<input class="input" type="text" placeholder="请输入内容">
</div>
</template>
然后,在style中添加以下样式:
<style>
.input-container {
position: relative;
width: 200px;
height: 50px;
}
.input {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
outline: none;
background-color: transparent;
font-size: 16px;
padding: 10px;
box-sizing: border-box;
transition: all 0.3s ease;
}
.input:focus {
border-bottom: 2px solid #007aff;
}
.input:focus + label {
transform: translateY(-20px);
font-size: 12px;
color: #007aff;
}
.input + label {
position: absolute;
top: 0;
left: 0;
font-size: 16px;
color: #999;
transform-origin: left top;
transition: all 0.3s ease;
pointer-events: none;
}
</style>
最后,在script中添加以下代码:
<script>
export default {
name: 'input-animation',
data() {
return {
inputValue: ''
}
}
}
</script>
这样就完成了一个简单的input输入动画效果,当用户点击输入框时,底部会出现一个蓝色的下划线,并且输入框上方的placeholder会向上移动一些,变成灰色的小字。
阅读全文
相关推荐

















