前端沉浸式输入体验效果

通过css的缩放功能以及动画效果,来实现一个输入框中的内容放大跟缩小,给用户一种沉浸式的感觉。效果图如下:


可以看到输入的内容,以一种飞入式的效果填充到输入框内,给人一种沉浸式的感觉(因为是图片演示,效果可能不佳)

完整代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>沉浸式输入</title>
<script src="https://cdn.staticfile.org/vue/2.7.0/vue.min.js"></script>
<style type="text/css">
 body{
 background-image: linear-gradient(120deg, #3d3d40 0%, #154d68 100%);
 overflow:hidden;
 }
 .content{
 position: absolute;
 height: 200px;
 top: 30%;
 left: 38%;
 }
 h1{
 text-align: center;
 color: white;
 }
 input{
 width: 350px;
 height: 30px;
 border:none;
 border-radius: 4px;
 color: transparent;
 }
 input:focus{
 outline:none;
 }
 .keywords {
 animation: fly 0.2s 1 ease-in-out;
 }
 @keyframes fly {
 from{
 position:absolute;
 transform: scale(60);
 }
 99% {
 position:absolute;
 }
 to {
 position:relative;
 }
 }
</style>
</head>
<body>
 
<div id="app">
 <div class="content">
 <h1>请输入搜索内容</h1>
 <input maxlength="30" type="text" v-model="keywords"/>
 <div style="position: absolute;top: 45%;left: 2%;font-weight: bold;">
 <span class="keywords" v-for="keys in showUp">{{keys}}</span>
 </div>
 </div>
</div>
<script>
new Vue({
 el: '#app',
 data: {
 keywords: ''
 },
 computed: {
 showUp: function(){
 return this.keywords;
 }
 }
})
</script>
</body>
</html>

总结:

1.input标签需要先将其内外边框以及光标都隐藏起来

2.在input标签上放一个div标签,用来显示输入的内容

3.通过vue的v-for指令,将每次输入的内容循环显示出来

作者:Winn原文地址:https://segmentfault.com/a/1190000043828659

%s 个评论

要回复文章请先登录注册