本文主要和大家介紹了CSS 動畫實現動態氣泡背景的方法的相關資料,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟著小編過來看看吧,希望能幫助大家。
今天的第一個任務是寫個登入頁面,老闆給了我一個參(chao)考(xi)案例,大家點擊連結就能看到。嗯,這個登入頁面確實很簡潔、大方,尤其是它的氣泡背景,第一反應這應該是張動態圖片,打開審查元素才發現原來這是用代碼寫的,一下子激起了寶寶的好奇心,所以也試著寫了一個帶有氣泡背景的登入頁面,效果如下:
#emm...為什麼上傳的gif 動態圖總是這麼小,來補張截圖:
(大家可以自行腦補這些背景氣泡往上升的畫面:sob:)
只需一些簡單的程式碼就可以實現這樣的效果,
首先我們先定義10個li 清單標籤,我用的是vue 框架:
##
<ul class="bg-bubbles"> <li v-for="(item, index) in bubbles" :key="index"></li> </ul>
##
created() { this.bubbles.length = 10; },
樣式是用less 寫的:
.bg-bubbles { position: absolute; // 使气泡背景充满整个屏幕 top: 0; left: 0; width: 100%; height: 100%; li { position: absolute; // bottom 的设置是为了营造出气泡从页面底部冒出的效果; bottom: -160px; // 默认的气泡大小; width: 40px; height: 40px; background-color: rgba(255, 255, 255, 0.15); list-style: none; // 使用自定义动画使气泡渐现、上升和翻滚; animation: square 15s infinite; transition-timing-function: linear; // 分别设置每个气泡不同的位置、大小、透明度和速度,以显得有层次感; &:nth-child(1) { left: 10%; } &:nth-child(2) { left: 20%; width: 90px; height: 90px; animation-delay: 2s; animation-duration: 7s; } &:nth-child(3) { left: 25%; animation-delay: 4s; } &:nth-child(4) { left: 40%; width: 60px; height: 60px; animation-duration: 8s; background-color: rgba(255, 255, 255, 0.3); } &:nth-child(5) { left: 70%; } &:nth-child(6) { left: 80%; width: 120px; height: 120px; animation-delay: 3s; background-color: rgba(255, 255, 255, 0.2); } &:nth-child(7) { left: 32%; width: 160px; height: 160px; animation-delay: 2s; } &:nth-child(8) { left: 55%; width: 20px; height: 20px; animation-delay: 4s; animation-duration: 15s; } &:nth-child(9) { left: 25%; width: 10px; height: 10px; animation-delay: 2s; animation-duration: 12s; background-color: rgba(255, 255, 255, 0.3); } &:nth-child(10) { left: 85%; width: 160px; height: 160px; animation-delay: 5s; } } // 自定义 square 动画; @keyframes square { 0% { opacity: 0.5; transform: translateY(0px) rotate(45deg); } 25% { opacity: 0.75; transform: translateY(-400px) rotate(90deg) } 50% { opacity: 1; transform: translateY(-600px) rotate(135deg); } 100% { opacity: 0; transform: translateY(-1000px) rotate(180deg); } } }
至此,一個氣泡背景圖就完成了。回過頭來看,確實不難,但也愈來愈讓人感受到 css 動畫的魅力和強大 :relaxed:。
相關推薦:
以上是CSS實現動態氣泡背景程式碼分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

Wufoo一直在集成方面非常出色。他們與特定應用程序(例如廣告系列顯示器,MailChimp和Typekit)進行集成,但他們也


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
刺客信條陰影:貝殼謎語解決方案
2 週前ByDDD
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
4 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

禪工作室 13.0.1
強大的PHP整合開發環境