77 lines
1.8 KiB
HTML
77 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>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
height: 100vh;
|
|
position: relative;
|
|
}
|
|
span {
|
|
position: absolute;
|
|
transition: all 1.5s;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
</body>
|
|
<script>
|
|
|
|
// 1: 在网页任意一个地方点击可以生成一个标签(颜色是随机的颜色)
|
|
//
|
|
// 向标签内一次插入 12字 方针
|
|
// 放标签放到网页上(鼠标点击的地方)
|
|
|
|
// 2: 让文字向上运动起来
|
|
|
|
// 3: 让文字消失
|
|
var index = 0
|
|
$("body").onclick = function (e) {
|
|
var x = e.x,
|
|
y = e.y - 21;
|
|
|
|
var text = ["富强", "民主", "文明", "和谐", "自由", "平等", "公正" ,"法治", "爱国", "敬业", "诚信", "友善"]
|
|
|
|
var span = document.createElement("span")
|
|
|
|
span.innerText = text[index];
|
|
span.style = `
|
|
left: ${x}px;
|
|
top: ${y}px;
|
|
opacity: 1;
|
|
color: hsla(${parseInt(Math.random() * 360)},100%,50%,1)
|
|
`
|
|
|
|
$("body").appendChild(span)
|
|
|
|
motion(span, x,y)
|
|
|
|
index+=1
|
|
if (index > 11) {
|
|
index = 0
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function motion(el,x,y) {
|
|
setTimeout(function () {
|
|
el.style.top = `${y - 100}px`
|
|
el.style.opacity = 0
|
|
}, 100)
|
|
setTimeout(function () {
|
|
$("body").removeChild(el)
|
|
}, 1600)
|
|
}
|
|
|
|
|
|
function $(className) {
|
|
return document.querySelector(className)
|
|
}
|
|
</script>
|
|
</html> |