微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vue input 组件 获焦上移

 

 

 

 

<template>
<div class="form">
<div class="inputForm">
<input :value="value" @input="handleInput" required="required">
<label>{{ label }}</label>
</div>
</div>

</template>
<script>
export default {
props: {
value: {
type: String,
default: "",
},
label: {
type: String,
default: "",
},
},
methods: {
handleInput(e) {
this.$emit("input", e.target.value);
},
},
};
</script>

<style scoped>
.form{
margin: 0.2rem 0.02rem;
width: 6rem;
border: 0.01rem solid red;
padding: 0 0.19rem;
}
.inputForm{
position: relative;
margin-top: 0.25rem;
}
.inputForm input{
outline: none;
border: none;
width: 100%;
padding: 0.1rem 0;
color: #000;
font-size: 0.16rem;
background: none;
}
.inputForm label{
position: absolute;
top: -0.09rem;
left: 0;
color: #000;
font-size: 0.29rem;
pointer-events: none;
/*加个过度*/
transition: all 0.5s;
}


.inputForm input:focus + label,
.inputForm input:valid + label{
font-size: 0.21rem;
top: -0.2rem;
color: red
}
</style>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐