本帖最后由 sun-cn 于 2022-6-23 16:19 编辑
cssbody {
margin: 0 auto;
background: rgb(0, 0, 0);
overflow: hidden;
}
.particle_star {
width:4px;
height:4px;
position:absolute;
background-color: rgb(255, 255, 255);
box-shadow:0px 0px 17px 4px rgb(245, 222, 179);
border-radius: 50%;
}
.container {
margin: 0 auto;
height: 100vh;
position: relative;
overflow: hidden;
background-size: 100% auto;
background-repeat: no-repeat;
background-image: url('../img/preview.png');
}
js
Hello worldvar x=document.getElementsByTagName("p");
for(var i=0; i< x.length; i++)
{
x[i].innerText="Hello world";
}
indexvar star_num = 75;
var $container = $(".container");
var $containerWidth = $container.width();
var $containerHeight = $container.height();
for (var i = 0; i < star_num; i++) {
var star = $('<div class="particle_star"></div>');
TweenLite.set(star, {
x: Math.random() * $containerWidth,
y: Math.random() * $containerHeight
});
$container.append(star);
star_fly(star);
}
function star_fly(elm) {
var fly = new TimelineMax();
var twinkle = new TimelineMax({
delay: Math.floor(Math.random() * 2) + 1,
repeatDelay: Math.floor(Math.random() * 6) + 1,
repeat: -1
});
twinkle.to(
[elm],
0.25,
{ opacity: 0.25, yoyo: true, repeat: 1, repeatDelay: 0.2, yoyo: true },
Math.floor(Math.random() * 6) + 1
);
fly
.set(elm, {scale: Math.random() * 1.75 + 0.5})
.to(elm, Math.random() * 100 + 100, {
bezier: {
values: [
{
x: Math.random() * $containerWidth,
y: Math.random() * $containerHeight
},
{
x: Math.random() * $containerWidth,
y: Math.random() * $containerHeight
}
]
},
onComplete: star_fly,
onCompleteParams: [elm]
});
}
后面两个js代码我的编译器无法解析可能有亿点乱
感谢大佬 |