81 lines
1.8 KiB
HTML
81 lines
1.8 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>
|
||
<link rel="stylesheet" href="./css/clear.css">
|
||
<style>
|
||
body {
|
||
height: 100vh;
|
||
position: relative;
|
||
}
|
||
|
||
span {
|
||
position: absolute;
|
||
user-select: none;
|
||
transition: all 0.8s ease;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
|
||
</body>
|
||
<script>
|
||
// 在你点击位置生产 span 标签
|
||
|
||
// 让span标签运动起来
|
||
|
||
var Text = ["富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善"];
|
||
var index = 0;
|
||
// 定义下标
|
||
|
||
// Math.random() * (max - min) + min
|
||
$("body").onclick = (e) => {
|
||
|
||
var { x, y } = e;
|
||
console.log(x, y)
|
||
|
||
var span = document.createElement("span")
|
||
console.dir(span)
|
||
span.innerText = Text[index];
|
||
span.style = `
|
||
left:${x}px;
|
||
top:${y}px;
|
||
color:hsl(${parseInt(Math.random() * 360)},100%,50%)
|
||
`
|
||
// 取随机数整数
|
||
|
||
index++
|
||
index > 11 ? index = 0 : '';
|
||
// 判断条件 ? 当条件为真执行 : 当条件为假执行
|
||
console.log(span)
|
||
|
||
$("body").appendChild(span)
|
||
// 把子容器span追加在父容器body里面
|
||
// span为虚拟dom,不能是字符串
|
||
motion(span, y)
|
||
}
|
||
|
||
|
||
function motion(el,y) {
|
||
setTimeout(() => {
|
||
el.style.top = `${y - 100}px`
|
||
}, 100)
|
||
|
||
setTimeout(() => {
|
||
$("body").removeChild(el)
|
||
}, 900)
|
||
}
|
||
|
||
|
||
// 获取单个标签
|
||
function $(className) {
|
||
return document.querySelector(className)
|
||
}
|
||
</script>
|
||
|
||
</html> |