<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>主页</title>
<style>
body {
margin: 0;
}
html {
margin: 0;
}
.title {
font-size: 35px;
font-weight: bolder;
text-align: center;
background-color: #3b858f;
color: rgb(0 0 0 / 53%);
height: 65px;
line-height: 65px;
}
#jail {
background-color: #f8767b;
top: 20px;
{#如果需要靠左边就设置成23%,百分比代表的是中心距离左边的距离#}
left: 50%;
}
#jail:hover {
background-color: #f5343b;
}
#hub {
background-color: #fac27c;
top: 150px;
left: 50%;
}
#hub:hover {
background-color: #fca331;
}
#TianLinZhai {
background-color: #ccf6a8;
top: 280px;
left: 50%;
}
#TianLinZhai:hover {
background-color: #89ef31;
}
#toilet {
background-color: #b0fae7;
top: 410px;
left: 50%;
}
#toilet:hover {
background-color: #0eeab1;
}
#rubbish {
background-color: #a2cbf3;
top: 540px;
left: 50%;
}
#rubbish:hover {
background-color: #4098ef;
}
.son {
width: 650px;
height: 100px;
margin-bottom: 20px;
border-radius: 30px;
text-align: center;
font-size: 32px;
line-height: 100px;
color: white;
position: absolute;
transform: translateX(-50%);
}
.son:hover {
transition: all 0.3s;
}
#particles-js {
position: relative;
background-color: #032d83
}
</style>
</head>
<body>
<div class="title">欢迎使用,请选择下方功能!</div>
<div id="particles-js">
<div id="jail" class="son" onclick="clickJail()">功能1</div>
<div id="hub" class="son" onclick="clickHub()">功能2</div>
<div id="TianLinZhai" class="son" onclick="clickTianLin()">功能3</div>
<div id="toilet" class="son" onclick="clickToi()">功能4</div>
<div id="rubbish" class="son" onclick="clickRub()">功能5</div>
</div>
<script>
function clickJail() {
//路由的路径
window.location.href = "#";
}
function clickHub() {
window.location.href = "#";
}
function clickTianLin() {
window.location.href = "#";
}
function clickToi() {
window.location.href = "#";
}
function clickRub() {
window.location.href = "#";
}
</script>
//particle.js库
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
<script>
var id = document.getElementsByClassName("particles-js")
console.log(id)
particlesJS("particles-js", {
// 粒子的基本配置
particles: {
number: {
value: 300, // 粒子数量
density: {
enable: true,
value_area: 800, // 粒子分布密度
},
},
color: {
value: "#fff", // 粒子颜色
},
shape: {
type: "circle", // 粒子形状,支持 circle(圆形)等
stroke: {
width: 0,
color: "#000000",
},
polygon: {
nb_sides: 5,
},
},
opacity: {
value: 0.5, // 粒子透明度
random: false,//随机透明度
anim: {
enable: false,//渐变动画
speed: 1,//渐变动画速度
opacity_min: 0.1,//不透明度
sync: false,
},
},
size: {
value: 5, // 粒子大小
random: true,//随机大小
anim: {
enable: true,//渐变
speed: 40,
size_min: 0.1,
sync: false,
},
},
line_linked: {
enable: true,
distance: 150, // 粒子间连线的距离
color: "#fff", // 粒子间连线的颜色
opacity: 0.4, // 粒子间连线的透明度
width: 1, // 粒子间连线的宽度
},
move: {
enable: true,//粒子移动
speed: 4, // 粒子运动速度
direction: "none",
random: false,
straight: false,
out_mode: "out",
bounce: false,
attract: {
enable: false,
rotateX: 600,
rotateY: 1200,
},
},
},
// 交互性的配置
interactivity: {
detect_on: "canvas",
events: {
onhover: {
enable: true,
mode: "repulse", // 鼠标悬停效果
},
onclick: {
enable: true,
mode: "push", // 鼠标点击效果
},
},
modes: {
grab: {
distance: 400,
line_linked: {
opacity: 1,
},
},
bubble: {
distance: 400,
size: 40,
duration: 2,
opacity: 8,
speed: 3,
},
repulse: {
distance: 130,//离心效果半径
duration: 0.4,
},
push: {
particles_nb: 4,
},
remove: {
particles_nb: 2,
},
},
},
retina_detect: true,
});
</script>
</body>
</html>
particle.js实现的前端粒子效果(可交互)(成品代码)
于 2024-03-15 16:20:17 首次发布