共计 1166 个字符,预计需要花费 3 分钟才能阅读完成。
通过 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 指令,将每次输出的内容循环显示进去
正文完