這里分享一個我平時常用的水波特效步驟,加在按鈕上特好使。
首先,是直接創建一個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>
效果圖
ss3給我們前端開發帶來了很便利, 我們可以使用css3
132個特效,是我歷時10個多月在油管一個一個跟著敲出來的,為了加強記憶,每個練習,我都錄制了視頻,在這里分享出來給大家。大家可能又會調侃了,你是工作不飽和吧,有時間做這些。其實,我目前工作還是挺飽和的,都是擠出來的。我們是9點上班,我基本7點半就到公司自學了,這樣我就有一個半小時的時間來做這些了。
對于 CSS 評價,無論是在論壇還是身邊的人,我聽到最多的是學 CSS 這些花里胡哨沒啥用,實際項目中又用不到。聽到這些心里還是挺實受挫的,有時候會懷疑自己,我學習的方向是不是錯了。但在幾次的項目需要用到一些特效,我都能很快的找到思路并做出來,我想這是得益于,我平時所學的這些特效積累出來的。
現在我不在困惑我所學的東西,因為學習成長是你自己事情,而不是別人在意的眼光。
對應的所有視頻可以到 【B站查看】,或者在 B 站搜索 前端小智 即可看到,源碼都在視頻簡介里面,大家進行查看。
效果:
視頻地址:https://www.bilibili.com/video/BV17V411r74q/
效果:
頻地址:https://www.bilibili.com/video/BV16Z4y1u7NY/
效果:
視頻地址:https://www.bilibili.com/video/BV1dK411J7p2/
效果:
視頻地址:https://www.bilibili.com/video/BV1bA411Y7UY/
演示視頻:https://www.bilibili.com/video/BV1Mh411Z7Ze/
演示視頻:https://www.bilibili.com/video/BV16f4y1X7Yr/
視頻地址:https://www.bilibili.com/video/BV14A411Y7Gd/
視頻地址:https://www.bilibili.com/video/BV1oD4y1U7C8/
視頻地址:https://www.bilibili.com/video/BV1vT4y157Up/
視頻地址:https://www.bilibili.com/video/BV1tf4y1979Z/
視頻地址:https://www.bilibili.com/video/BV1EV411U7fD/
視頻地址:https://www.bilibili.com/video/BV1sA411n7us/
視頻地址:https://www.bilibili.com/video/BV1eZ4y1K7o3/
視頻地址:https://www.bilibili.com/video/BV1tK4y1Y771/
視頻地址:https://www.bilibili.com/video/BV1V5411h7iZ/
視頻地址:https://www.bilibili.com/video/BV1Dh41197Lf/
視頻地址:https://www.bilibili.com/video/BV145411b7RJ/
視頻播放地址:https://www.bilibili.com/video/BV15D4y1m7JG/
視頻演示地址:https://www.bilibili.com/video/BV1Lf4y1X7Bm/
視頻地址:https://www.bilibili.com/video/BV1YA411n7xu/
視頻地址:https://www.bilibili.com/video/BV1vA411E77W/
視頻地址:https://www.bilibili.com/video/BV17T4y1A7Vg/
視頻地址:https://www.bilibili.com/video/BV1s5411b78Q/
視頻地址:https://www.bilibili.com/video/BV1KZ4y1N7nr/
視頻地址:https://www.bilibili.com/video/BV1Jf4y1D7Lm/
視頻地址:https://www.bilibili.com/video/BV17A411J7RL/
視頻地址:https://www.bilibili.com/video/BV1yv411C7NJ/
視頻地址:https://www.bilibili.com/video/BV1RV411m7LQ/
視頻地址:https://member.bilibili.com/v2#/upload-manager/article
視頻地址:https://www.bilibili.com/video/BV1LK411A7X2/
視頻地址:https://www.ixigua.com/6882247186009031181/
視頻地址:https://www.ixigua.com/6882247186009031181/
視頻地址:https://www.ixigua.com/6883784380632793611/
視頻地址:https://www.ixigua.com/6885309534483513859/
視頻地址:https://www.ixigua.com/6886389124811457032/
視頻地址:https://www.ixigua.com/6887878632572715532/
視頻地址:https://www.ixigua.com/6888608009556230667/
視頻地址:https://www.ixigua.com/6890835336868397572/
視頻地址:https://www.ixigua.com/6891580915374359043/
視頻地址:https://www.ixigua.com/6893066211257483784/
視頻地址:https://www.ixigua.com/6893808422605554183/
視頻地址:https://www.ixigua.com/6894533882432094728/
視頻地址:https://www.ixigua.com/6897449872975200780/
視頻地址:https://www.ixigua.com/6897450763094753800/
視頻地址:https://www.ixigua.com/6898262151455048199/
視頻地址:https://www.ixigua.com/6899588911862022660/
視頻地址:https://www.ixigua.com/6901230535520027143/
視頻地址:https://www.ixigua.com/6902344348986262024/
視頻地址:https://www.ixigua.com/6903449899006689804/
視頻地址:https://www.ixigua.com/6904504548409213454/
視頻地址:https://www.ixigua.com/6906066035506414084/
視頻地址:https://www.ixigua.com/6906796258489270788/
視頻地址:https://www.ixigua.com/6907873173098889731/?&wid_try=1
視頻地址: https://www.bilibili.com/video/BV1964y1f7CK/
視頻地址:https://www.ixigua.com/6910132650648797699/
視頻地址:https://www.ixigua.com/6911265897659400708/
視頻地址:https://www.ixigua.com/6911983867603878407/
視頻地址:https://www.ixigua.com/6914222592170263053/
視頻地址:https://www.ixigua.com/6914589524660224526/
視頻地址:https://www.ixigua.com/6915324225184072200/
視頻地址:https://www.ixigua.com/6916439319217603085/
視頻地址:https://www.ixigua.com/6917189337700368907/
視頻地址:https://www.ixigua.com/6917930699139842563
視頻地址:https://www.ixigua.com/6919046116382081540
完~,我是小智,我要去刷碗了,我們下期再見!
*請認真填寫需求信息,我們會在24小時內與您取得聯系。