易的CSS3炫酷3D滾動預覽特效, 3D旋轉展示!
效果圖:
實現代碼:
html:
css:
javascript:
這里分享一個我平時常用的水波特效步驟,加在按鈕上特好使。
首先,是直接創建一個div盒子,不需要在里面添加其他內容,我們直接對盒子本身添加css就能形成水波效果。
html部分,我們div添加白色的波紋,所以在這里設置html背景為藍色。
<body style="background-color: cadetblue ;">
<div class="video"></div>
</body>
css部分,先設置好div的基本屬性
.video {
/* 基本屬性 */
width: 100px;
height: 100px;
border-radius: 50px;
/* 給背景顏色添加不透明度 */
/* 不透明度還可以通過添加opacity屬性修改 */
background-color: rgb(255, 255, 255, 0.6);
}
然后就是在video中添加這個特效中重中之重的內容,在css中設置animation。
Animation 是由三部分組成。
.video {
/* 添加ripple動畫效果 */
/* -webkit-animation適配-webkit內核的瀏覽器*/
-webkit-animation: ripple 1s linear infinite;
animation: ripple 1s linear infinite;
}
/* 定義ripple動畫效果 */
@-webkit-keyframes ripple {
/* 關鍵幀播放到0%時的狀態 */
0% {
/* 在box四周添加三層白色陰影 */
box-shadow: 0 0 0 0 rgb(255 255 255 / 25%),
0 0 0 10px rgb(255 255 255 / 25%),
0 0 0 20px rgb(255 255 255 / 25%);
}
/* 關鍵幀播放到100%時的狀態 */
100% {
/* 分別改變三層陰影的距離
形成兩幀的動畫,然后在transition的過渡下形成動畫 */
box-shadow: 0 0 0 10px rgb(255 255 255 / 25%),
0 0 0 20px rgb(255 255 255 / 25%),
0 0 0 40px rgba(50, 100, 245, 0);
}
}
/* 多種瀏覽器兼容性設置 */
@keyframes ripple {
0% {
box-shadow: 0 0 0 0 rgb(255 255 255 / 25%),
0 0 0 10px rgb(255 255 255 / 25%),
0 0 0 20px rgb(255 255 255 / 25%);
}
100% {
box-shadow: 0 0 0 10px rgb(255 255 255 / 25%),
0 0 0 20px rgb(255 255 255 / 25%),
0 0 0 40px rgba(50, 100, 245, 0);
}
}
其中,linear是表示動畫的timing-function,其總共大致有以下幾種效果。
圖源水印
為了實現按鈕的響應式操作,我們可以給div再加上一個hover選擇器
/* 鼠標懸浮時的狀態 */
.video:hover {
/* 背景顏色不透明度變化 */
background-color: #FFFFFF;
/* 將對象放大1.2倍 */
transform: scale(1.2);
}
再給div添加一個transition屬性,讓div在鼠標移動的時候能自然過渡,其原理跟animation類似。
.video {
/* 添加動畫的過渡效果 */
transition: all 0.3s ease-in-out;
}
然后就能得到我們的結果,整體的代碼如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.video {
width: 100px;
height: 100px;
border-radius: 50px;
background-color: rgb(255, 255, 255, 0.6);
transition: all 0.3s ease-in-out;
-webkit-animation適配-webkit內核的瀏覽器*/
-webkit-animation: ripple 1s linear infinite;
animation: ripple 1s linear infinite;
}
.video:hover {
background-color: #FFFFFF;
transform: scale(1.2);
}
@-webkit-keyframes ripple {
0% {
/* 在box四周添加三層白色陰影 */
box-shadow: 0 0 0 0 rgb(255 255 255 / 25%),
0 0 0 10px rgb(255 255 255 / 25%),
0 0 0 20px rgb(255 255 255 / 25%);
}
100% {
/* 分別改變三層陰影的距離
形成兩幀的動畫,然后在transition的過渡下形成動畫 */
box-shadow: 0 0 0 10px rgb(255 255 255 / 25%),
0 0 0 20px rgb(255 255 255 / 25%),
0 0 0 40px rgba(50, 100, 245, 0);
}
}
@keyframes ripple {
0% {
box-shadow: 0 0 0 0 rgb(255 255 255 / 25%),
0 0 0 10px rgb(255 255 255 / 25%),
0 0 0 20px rgb(255 255 255 / 25%);
}
100% {
box-shadow: 0 0 0 10px rgb(255 255 255 / 25%),
0 0 0 20px rgb(255 255 255 / 25%),
0 0 0 40px rgba(50, 100, 245, 0);
}
}
</style>
</head>
<body style="background-color: cadetblue ;">
<div class="video"></div>
</body>
</html>
效果圖
下是使用HTML、CSS和JavaScript實現"櫻花飄落"和"雪花飄落"特效的簡單示例:
1. 櫻花飄落特效:
HTML:
```html
<div class="sakura-container">
<img src="sakura.png" class="sakura" alt="sakura">
</div>
```
CSS:
```css
.sakura-container {
position: relative;
height: 100vh;
overflow: hidden;
}
.sakura {
position: absolute;
top: -50px;
animation: sakura-fall 10s linear infinite;
}
@keyframes sakura-fall {
0% {
transform: translateY(0);
}
100% {
transform: translateY(100vh);
}
}
```
2. 雪花飄落特效:
HTML:
```html
<div class="snow-container">
<span class="snowflake"></span>
</div>
```
CSS:
```css
.snow-container {
position: relative;
height: 100vh;
overflow: hidden;
background-color: #000;
}
.snowflake {
position: absolute;
top: -10px;
width: 10px;
height: 10px;
background-color: #fff;
border-radius: 50%;
animation: snow-fall 5s linear infinite;
}
@keyframes snow-fall {
0% {
transform: translateY(0) rotate(0deg);
}
100% {
transform: translateY(100vh) rotate(360deg);
}
}
```
JavaScript:
```javascript
function createSnowflakes() {
const snowContainer = document.querySelector('.snow-container');
const numFlakes = 50;
for (let i = 0; i < numFlakes; i++) {
const snowflake = document.createElement('span');
snowflake.classList.add('snowflake');
snowflake.style.left = `${Math.random() * 100}%`;
snowflake.style.animationDelay = `${Math.random() * 5}s`;
snowContainer.appendChild(snowflake);
}
}
createSnowflakes();
```
將上述代碼保存為HTML文件,并在相應的位置放置櫻花或雪花圖像,即可實現對應特效。注意,需要在CSS中調整圖像和容器的樣式以適應實際需求。這只是一個簡單示例,您可以根據自己的喜好和需求進行定制和擴展。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。