76 lines
1.7 KiB
HTML
76 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Document</title>
|
||
<style>
|
||
body,
|
||
html {
|
||
width: 100%;
|
||
height: 100%;
|
||
margin: 0;
|
||
}
|
||
|
||
span {
|
||
position: fixed;
|
||
transition: all 0.9s;
|
||
user-select: none;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
|
||
</body>
|
||
|
||
<script>
|
||
// 给body绑定点击事件,点击的时候动态获取 鼠标的 x,y 坐标
|
||
// 使用js动态的去创建标签,设置定位属性,再设置left top 数值,再使用hsla来设置随机颜色, 最后将span标签放到
|
||
// 网页上
|
||
|
||
|
||
//
|
||
|
||
|
||
|
||
var text = ["富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善"];
|
||
var index = 0;
|
||
$("body").onclick = (event) => {
|
||
var X = event.clientX, Y = event.clientY;
|
||
|
||
var span = document.createElement("span");
|
||
span.style.left = `${X}px`;
|
||
span.style.top = `${Y}px`;
|
||
span.style.color = `hsla(${parseInt(Math.random() * 360)},100%,50%,1)`;
|
||
span.innerText = text[index];
|
||
index += 1;
|
||
index > 11 ? index = 0 : ''
|
||
|
||
|
||
$("body").appendChild(span)
|
||
|
||
motion(span)
|
||
}
|
||
|
||
|
||
function motion(el) {
|
||
setTimeout(() => {
|
||
el.style.top = `${parseInt(el.style.top) - 150}px`
|
||
}, 100)
|
||
|
||
setTimeout(() => {
|
||
$("body").removeChild(el)
|
||
}, 1100)
|
||
}
|
||
|
||
|
||
|
||
function $(className) {
|
||
return document.querySelector(className)
|
||
}
|
||
</script>
|
||
|
||
</html> |