首頁 雲端運算與程式碼文章正文

一個簡單的html大海日出特效的代碼

雲端運算與程式碼 2023年05月11日 18:04 745 訪客

以下是一個簡單的html大海日出特效的代碼:


一個簡單的html大海日出特效的代碼 第1张

```html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>大海日出特效</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #000;
}
#ocean {
position: relative;
width: 100%;
height: 500px;
overflow: hidden;
}
#sun {
position: absolute;
z-index: 2;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100px;
height: 100px;
border-radius: 50%;
background-color: #fa803a;
box-shadow: 0px 0px 30px 10px #f9aa33;
animation: sun-rise 8s linear forwards;
}
@keyframes sun-rise {
from {
top: 100%;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 0;
opacity: 0;
}
to {
top: 20%;
left: 10%;
width: 200px;
height: 200px;
opacity: 1;
}
}
#water {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to bottom, #1e87c9, #119bd1, #4db8e8, #75c9e9, #1e87c9);
animation: water-anime 10s linear infinite;
}
@keyframes water-anime {
from {
background-position: 0% 50%;
}
to {
background-position: 100% 50%;
}
}
</style>
</head>
<body>
<div id="ocean">
<div id="water"></div>
<div id="sun"></div>
</div>
</body>
</html>

```


代碼說明:


1. 使用html和css定義了一個大海和太陽的基本樣式;

2. 使用animation讓太陽從初始位置向上升起,並且設置好其動畫屬性;

3. 設置大海背景漸變和水面的動畫效果。

標籤: html大海日出特效的代碼

AmupuCopyright Amupu.Z-Blog.Some Rights Reserved.