webgl实现逼真海上日出日落6场景滚动切换动画代码

代码语言:html

所属分类:动画

代码描述:webgl实现逼真海上日出日落6场景滚动切换动画代码

代码标签: webgl 逼真 海上 日出 日落 6 场景 滚动 切换 动画 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;700&family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">

  
  
  
<style>
*,
*::before,
*::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

:root {
	/* Set by JS per scene — defaults to dawn */
	--fg: #f0cfa0;
	--fg-dim: rgba(240, 207, 160, 0.55);
	--fg-hud: rgba(240, 207, 160, 0.7);
	--fg-dot: rgba(240, 207, 160, 0.3);
	--fg-dotact: rgba(240, 207, 160, 0.9);
	--bg: #0a0a0f;
	--accent: #a0b4ff;
	--scrim: 0.18;
}

html {
	scroll-behavior: auto;
}

body {
	background: var(--bg);
	color: var(--fg);
	font-family: "Space Grotesk", sans-serif;
	overflow-x: hidden;
	cursor: crosshair;
}

/* ── Fixed canvas ─────────────────────────────────────── */
#webgl_canvas {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	z-index: 0;
	display: block;
}

/* ── HUD ──────────────────────────────────────────────── */
#hud {
	position: fixed;
	inset: 0;
	z-index: 10;
	pointer-events: none;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	padding: 1.5rem 2rem;
}

#hud-top {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
}

#hud-bottom {
	display: flex;
	justify-content: space-between;
	align-items: flex-end;
}

.mono {
	font-family: "Space Mono", monospace;
}

#scene_name {
	font-family: "Space Mono", monospace;
	font-size: clamp(0.65rem, 1.5vw, 0.78rem);
	letter-spacing: 0.25em;
	text-transform: uppercase;
	color: var(--fg-hud);
	text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
	transition: color 1.2s ease;
}

#hud_pct {
	font-family: "Space Mono", monospace;
	font-size: clamp(0.65rem, 1.5vw, 0.78rem);
	letter-spacing: 0.12em;
	color: var(--fg-hud);
	opacity: 0.65;
	text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
	transition: color 1.2s ease;
}

#prog_bar {
	width: 120px;
	height: 2px;
	background: rgba(255, 255, 255, 0.15);
	position: relative;
	overflow: hidden;
	border-radius: 2px;
}
#prog_fill {
	position: absolute;
	left: 0;
	top: 0;
	bottom: 0;
	background: var(--fg-hud);
	opacity: 0.7;
	width: 0%;
	transition: width 80ms linear, background 1.2s ease;
}

/* Scene dots */
#scene_dots {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	position: fixed;
	right: 1.75rem;
	top: 50%;
	transform: translateY(-50%);
	z-index: 10;
	pointer-events: none;
}

.scene-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--fg-dot);
	transition: background 0.4s, transform 0.3s;
}

.scene-dot.active {
	background: var(--fg-dotact);
	transform: scale(1.5);
}

/* ── Scrollable content ───────────────────────────────── */
#scroll_track {
	position: relative;
	z-index: 5;
	pointer-events: none;
}

.scene-section {
	height: 100vh;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	padding: 0 2.5rem 4.5rem;
	pointer-events: none;
	position: relative;
}

/* Bottom scrim — gets more opaque as night approaches */
.scene-section::after {
	content: "";
	position: absolute;
	inset: 0;
	background: linear-gradient(
		to top,
		rgba(0, 0, 8, var(--scrim, 0.18)) 0%,
		rgba(0, 0, 8, calc(var(--scrim, 0.18) * 0.4)) 40%,
		transparent 70%
	);
	pointer-events: none;
	z-index: 0;
	transition: --scrim 0.5s;
}

.scene-section > * {
	position: relative;
	z-index: 1;
}

.scene-title {
	font-family: "Space Grotesk", sans-serif;
	font-weight: 700;
	font-size: clamp(2.8rem, 8vw, 6.5rem);
	line-height: 0.95;
	color: var(--fg);
	text-shadow: 0 2px 40px rgba(0, 0, 0, 0.7), 0 1px 4px rgba(0, 0, 0, 0.9);
	letter-spacing: -0.02em;
	opacity: 0;
	transform: translateY(18px);
	transition: opacity 0.7s ease, transform 0.7s ease, color 1.2s ease;
}

.scene-title.visible {
	opacity: 1;
	transform: none;
}

.scene-desc {
	font-family: "Space Grotesk", sans-serif;
	font-weight: 300;
	font-size: clamp(0.88rem, 2vw, 1.1rem);
	color: var(--fg);
	opacity: 0;
	max-width: 420px;
	margin-top: 0.75rem;
	line-height: 1.55;
	text-shadow: 0 1px 16px rgba(0, 0, 0, 0.85), 0 0px 4px rgba(0, 0, 0, 0.7);
	transform: translateY(10px);
	transition: opacity 0.7s ease 0.12s, transform 0.7s ease 0.12s, color 1.2s ease;
}

.scene-desc.visible {
	opacity: 0.88;
	transform: none;
}

/* h-line decorative */
.h-line {
	width: 36px;
	height: 1px;
	background: var(--fg);
	opacity: 0;
	margin-bottom: 1rem;
	transition: opacity 0.6s ease 0.05s, background 1.2s ease;
}

.h-line.visible {
	opacity: 0.4;
	width: 36px;
}

.scene-label {
	font-family: "Space Mono", monospace;
	font-size: clamp(0.58rem, 1.2vw, 0.72rem);
	letter-spacing: 0.3em;
	text-transform: uppercase;
	color: var(--fg);
	opacity: 0.45;
	margin-bottom: 0.5rem;
	transition: color 1.2s ease;
}
</style>


  
  
</head>

<body translate="no">
  <canvas id="webgl_canvas"></canvas>

<!-- HUD -->
<div id="hud">
	<div id="hud-top">
		<div>
			<div id="scene_name" class="mono">DAWN</div>
		</div>
		<div style="display:flex;flex-direction:column;align-items:flex-end;gap:0.4rem;">
			<div id="hud_pct" class="mono">000%</div>
			<div id="prog_bar">
				<div id="prog_fill"></div>
			</div>
		</div>
	</div>
	<div id="hud-bottom"></div>
</div>

<!-- Scene nav dots -->
<div id="scene_dots">
	<div class="scene-dot act.........完整代码请登录后点击上方下载按钮下载查看

网友评论0