很漂亮的星空图片制作

转载自:https://blog.csdn.net/qq_42381297/article/details/82655547?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

效果:

星空效果

源代码:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>太空</title>
	<style>
		body{
			width: 100%;
			height: 1000px;
			background: linear-gradient(to bottom right, #000, #2073c2 60%, #dff6ff);
			overflow: hidden;
		}
		span{
			display: block;
			position: absolute;
			border-radius: 50%;
			box-shadow: 0.4px 0.4px 0.4px 0px #fff;
		}
	</style>
</head>
<body>
 
<script>
	window.onload = function(){
		var screenW = document.documentElement.clientWidth;
		var screenH = document.documentElement.clientHeight;
		var colorArr = ['#fff','skyblue','orange'];
		console.log(screenW);
		for( var i=0; i<800; i++ ){
			var span = document.createElement('span');
			var width = Math.random() * 3;
			var colorIndex = parseInt(Math.random() * 3);
			var x = parseInt(Math.random() * screenW);
			var y = parseInt(Math.random() * screenH);
			span.style.width = parseInt(width) + 'px';
			span.style.height = parseInt(width) + 'px';
			span.style.background = colorArr[colorIndex];
			span.style.left = x + 'px';
			span.style.top = y + 'px';
 
			document.body.appendChild(span);
		}
	}
</script>
 
</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很高兴能回答你的问题!网页制作星空特效CSS可以通过设置背景图片和CSS动画来实现。首先,您需要准备一张星空背景图片,并将其设置为页面的背景,然后使用CSS动画添加星星的闪烁效果。 以下是一些示范代码: HTML代码: ``` <body> <div class="stars"></div> <div class="twinkling"></div> <div class="clouds"></div> </body> ``` CSS代码: ``` body { background: #000 url(stars.jpg) repeat top center; overflow: hidden; } .stars { background: transparent url(stars.png) repeat top center; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 0; } .twinkling { background: transparent url(twinkling.png) repeat top center; position: absolute; top: 0; left: 0; width: 100%; height: 100%; animation: move-twink-back 200s linear infinite; z-index: 1; } .clouds { background: transparent url(clouds.png) repeat top center; position: absolute; top: 0; left: 0; width: 100%; height: 100%; animation: move-clouds-back 200s linear infinite; z-index: 2; } @keyframes move-twink-back { 0% { background-position: 0 0; } 100% { background-position: 10000px 0; } } @keyframes move-clouds-back { 0% { background-position: 0 0; } 100% { background-position: 10000px 0; } } ``` 这个代码片段将星空背景图片设置为页面背景,然后使用CSS动画在星空中添加星星闪烁的效果,同时还添加了云层的移动效果。您可以添加更多的CSS动画来创建更多的效果,例如流星、星球等。希望这个答案能够帮助到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值