
目录
图片展示

完整代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>永夜星河主题特效</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
margin: 0;
overflow: hidden;
background: radial-gradient(circle, #1a2a6c, #b21f1f, #fdbb2d);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
position: relative;
}
/* 星星背景 */
canvas {
position: absolute;
top: 0;
left: 0;
}
/* 星河背景特效 */
#perspective {
perspective: 800px;
}
#wrap {
position: relative;
width: 150px;
height: 178px;
/* margin: 200px auto; */
transform-style: preserve-3d;
transform: rotateX(-20deg) rotateY(0deg);
}
#wrap .image-block {
position: absolute;
transform: rotateY(0deg);
}
#wrap .image-block img {
width: 150px;
height: 178px;
}
/* 闪烁文字 */
.title {
position: absolute;
top: 20%;
font-size: 3em;
font-weight: bold;
text-transform: uppercase;
text-shadow: 0 0 20px #fff, 0 0 30px #ff9, 0 0 40px #ff9;
animation: glow 2s infinite alternate;
}
@keyframes glow {
from {
text-shadow: 0 0 10px #fff, 0 0 20px #ff9, 0 0 30px #ff9;
}
to {
text-shadow: 0 0 30px #ff9, 0 0 50px #ff9, 0 0 70px #ff9;
}
}
/* 动态漂浮角色 */
/* 动态漂浮和旋转图片 */
.character {
position: absolute;
bottom: 10%;
width: 150px;
animation: float 4s ease-in-out infinite, rotate 6s linear infinite;
}
/* .character {
position: absolute;
bottom: 10%;
width: 150px;
animation: float 4s ease-in-out infinite;
} */
/* 旋转动画 */
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
/* 点击星星特效 */
.star {
position: absolute;
width: 5px;
height: 5px;
background-color: white;
border-radius: 50%;
box-shadow: 0 0 8px #fff;
animation: fade-out 2s forwards ease;
}
@keyframes fade-out {
0% {
opacity: 1;
transform: translateY(0) scale(1);
}
100% {
opacity: 0;
transform: translateY(-50px) scale(2);
}
}
/* 点击动态文字 */
.message {
position: absolute;
bottom: 5%;
font-size: 1.2rem;
text-align: center;
opacity: 0;
transition: opacity 1s ease;
}
/* 设置视角和容器 */
#perspective {
perspective: 1000px;
/* 设定透视效果 */
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
}
/* 容器中的图片块 */
#wrap {
position: absolute;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
transform-style: preserve-3d;
/* 保持3D效果 */
animation: rotateWrap 20s infinite linear;
/* 旋转容器 */
}
/* 图片块 */
.image-block {
position: absolute;
width: 150px;
/* 图片宽度 */
height: 150px;
/* 图片高度 */
transform-origin: center;
/* 旋转中心为图片的中心 */
}
/* 图片样式 */
.pic {
width: 100%;
height: 100%;
object-fit: cover;
/* 保持图片的比例 */
}
/* 旋转动画 */
@keyframes rotateWrap {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(360deg);
}
}
.reflection {
position: relative;
padding-left: 8px;
}
.reflection img {
transform: scaleY(-1);
opacity: 0.50;
}
.reflection .overlay {
position: absolute;
top: 0px;
left: 8px;
width: 150px;
height: 178px;
background: linear-gradient(to top, rgba(0, 0, 0, 0.5) 60%, rgba(0, 0, 0, 0) 75%);
}
</style>
</head>
<body>
<!-- 星河背景 -->
<canvas id="stars"></canvas>
<!-- 闪烁文字 -->
<div class="title">永夜星河</div>
<!-- 动态漂浮角色 -->
<!-- <img src="character.png" alt="角色" class="character"> -->
<!-- 提示文字 -->
<div class="message">点击屏幕,让星星带来惊喜!</div>
<!-- 3D 图片旋转特效 -->
<div id="perspective">
<div id="wrap">
<!-- 图片块 -->
<div class="image-block">
<img class="pic" src="img/1.jpg" />
<div class="reflection">
<img src="img/1.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/2.jpg" />
<div class="reflection">
<img src="img/2.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/3.jpg" />
<div class="reflection">
<img src="img/3.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/4.jpg" />
<div class="reflection">
<img src="img/4.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/5.jpg" />
<div class="reflection">
<img src="img/5.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/6.jpg" />
<div class="reflection">
<img src="img/6.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/14.jpg" />
<div class="reflection">
<img src="img/14.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/8.jpg" />
<div class="reflection">
<img src="img/8.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/9.jpg" />
<div class="reflection">
<img src="img/9.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/10.jpg" />
<div class="reflection">
<img src="img/10.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/11.jpg" />
<div class="reflection">
<img src="img/11.jpg" />
<div class="overlay"></div>
</div>
</div>
<div class="image-block">
<img class="pic" src="img/12.jpg" />
<div class="reflection">
<img src="img/12.jpg" />
<div class="overlay"></div>
</div>
</div>
</div>
<script>
// 星星背景特效
const canvas = document.getElementById('stars');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let stars = [];
const numStars = 100;
for (let i = 0; i < numStars; i++) {
stars.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
radius: Math.random() * 1.5,
speed: Math.random() * 0.5
});
}
function drawStars() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = 'white';
stars.forEach(star => {
ctx.beginPath();
ctx.arc(star.x, star.y, star.radius, 0, Math.PI * 2);
ctx.fill();
star.y += star.speed;
if (star.y > canvas.height) {
star.y = 0;
}
});
requestAnimationFrame(drawStars);
}
drawStars();
// 点击生成星星特效和动态文字
document.body.addEventListener('click', (e) => {
// 创建星星
const star = document.createElement('div');
star.classList.add('star');
star.style.left = `${e.clientX}px`;
star.style.top = `${e.clientY}px`;
document.body.appendChild(star);
// 移除星星
setTimeout(() => {
star.remove();
}, 2000);
// 显示动态文字
const text = document.createElement('div');
text.style.position = 'absolute';
text.style.left = `${e.clientX}px`;
text.style.top = `${e.clientY - 30}px`;
text.style.color = 'white';
text.style.fontSize = '1.2rem';
text.style.fontWeight = 'bold';
text.textContent = getRandomText();
document.body.appendChild(text);
// 移除文字
setTimeout(() => {
text.remove();
}, 2000);
});
function getRandomText() {
const texts = [
'星星闪烁,因为你在!',
'你好,星河女主角!',
'愿你像星星一样闪耀!',
'点亮我的夜空!',
'你是人间最亮的星~'
];
return texts[Math.floor(Math.random() * texts.length)];
}
// 3D 旋转图片特效
window.onload = function() {
var oImg = document.getElementsByClassName("image-block");
var deg = 360 / oImg.length; // 每张图片的旋转角度
var nowX, nowY, lastX, lastY, minsX, minsY, roX = -20,
roY = 0;
Array.prototype.forEach.call(oImg, function(el, index) {
el.style.transform = "rotateY(" + index * deg + "deg) translateZ(400px)";
el.style.transition = "1s " + (oImg.length - index) * 0.5 + "s";
});
document.onmousedown = function(e) {
var e = e || window.event;
lastX = e.clientX;
lastY = e.clientY;
this.onmousemove = function(e) {
var e = e || window.event;
nowX = e.clientX;
nowY = e.clientY;
minsX = nowX - lastX;
minsY = nowY - lastY;
roX -= minsY * 0.2;
roY += minsX * 0.2;
wrap.style.transform = "rotateX(" + roX + "deg) rotateY(" + roY + "deg)";
lastX = nowX;
lastY = nowY;
};
this.onmouseup = function() {
this.onmousemove = null;
this.onmouseup = null;
};
};
};
</script>
</body>
</html>
嗨,我是命运之光。如果你觉得我的分享有价值,不妨通过以下方式表达你的支持:👍 点赞来表达你的喜爱,📁 关注以获取我的最新消息,💬 评论与我交流你的见解。我会继续努力,为你带来更多精彩和实用的内容。
点击这里👉 ,获取最新动态,⚡️ 让信息传递更加迅速。



617




被折叠的 条评论
为什么被折叠?



