js实现input输入框输入文字烟花爆炸动画特效代码

代码语言:html

所属分类:动画

代码描述:js实现input输入框输入文字烟花爆炸动画特效代码

代码标签: js input 输入框 输入 文字 烟花 爆炸 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  
  <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Inconsolata&amp;display=swap'>
  
<style>
* {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
:root {
	--hue: 223;
	--bg: hsl(var(--hue),90%,15%);
	--fg: hsl(var(--hue),90%,90%);
	font-size: calc(20px + (60 - 20) * (100vw - 320px) / (1280 - 320));
}
body, input {
	color: var(--fg);
	font: 1em/1.5 Inconsolata, monospace
}
body {
	background: var(--bg);
	height: 100vh;
	display: grid;
	place-items: center;
}
input {
	background: transparent;
	border-radius: 0;
	box-shadow: 0 -1px 0 hsla(var(--hue),10%,90%,0.3) inset;
	width: 24ch;
	transition: box-shadow 0.15s linear;
	-webkit-appearance: none;
	appearance: none;
}
input:focus {
	box-shadow: 0 -1px 0 hsl(var(--hue),90%,90%) inset;
	outline: transparent;
}
input::placeholder {
	color: hsla(var(--hue),90%,90%,0.3);
}
.sr {
	clip: rect(1px,1px,1px,1px);
	overflow: hidden;
	position: absolute;
	width: 1px;
	height: 1px;
}
.particle {
	border-radius: 50%;
	pointer-events: none;
	position: fixed;
	width: 1.5ch;
	height: 1.5ch;
}
.particle--ring {
	box-shadow: 0 0 0 0.125em inset;
}
</style>


  
</head>

<body translate="no">
  <main>
	<label for="text" class="sr">Text</label>
	<input id="text" type="text" name="text" placeholder="Type something…" size="24" maxlength="24" spellcheck="false">
</main>
  
      <script  >
window.addEventListener("DOMContentLoaded",() => {
	const input = new TypingFireworks("#text");
});

class TypingFireworks {
	particles = 20;
	value = "";

	constructor(qs) {
		this.input = document.querySelector(qs);

		this.input?.addEventListener("input",this.fireworks.bind(this));
	}
	fireworks() {
		const { selectionStart, value } = this.input;
		const { length } = value;
		const { top, left, hei.........完整代码请登录后点击上方下载按钮下载查看

网友评论0