摘要:效果預覽按下右側的點擊預覽按鈕可以在當前頁面預覽,點擊鏈接可以全屏預覽??山换ヒ曨l教程此視頻是可以交互的,你可以隨時暫停視頻,編輯視頻中的代碼。
效果預覽
按下右側的“點擊預覽”按鈕可以在當前頁面預覽,點擊鏈接可以全屏預覽。
https://codepen.io/comehope/pen/ELpRxj
可交互視頻教程此視頻是可以交互的,你可以隨時暫停視頻,編輯視頻中的代碼。
請用 chrome, safari, edge 打開觀看。
https://scrimba.com/c/czrWDfZ
源代碼下載每日前端實戰系列的全部源代碼請從 github 下載:
https://github.com/comehope/front-end-daily-challenges
代碼解讀定義 dom,容器中包含文本,并且包含4個 用于特效, 的 data-text 屬性值為與文本相同:
web
居中顯示:
html, body {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: black;
}
定義文本樣式:
.rainbow {
color: white;
font-size: 300px;
text-transform: uppercase;
font-family: sans-serif;
font-weight: bold;
line-height: 1em;
position: relative;
}
用偽元素增加圖層,形成彩虹效果:
.rainbow span::before,
.rainbow span::after {
content: attr(data-text);
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
.rainbow span:nth-child(1)::before {
color: orchid;
z-index: 1;
height: calc(100% - 10% * 1);
}
.rainbow span:nth-child(1)::after {
color: mediumpurple;
z-index: 2;
height: calc(100% - 10% * 2);
}
.rainbow span:nth-child(2)::before {
color: deepskyblue;
z-index: 3;
height: calc(100% - 10% * 3);
}
.rainbow span:nth-child(2)::after {
color: cyan;
z-index: 4;
height: calc(100% - 10% * 4);
}
.rainbow span:nth-child(3)::before {
color: mediumspringgreen;
z-index: 5;
height: calc(100% - 10% * 5);
}
.rainbow span:nth-child(3)::after {
color: yellow;
z-index: 6;
height: calc(100% - 10% * 6);
}
.rainbow span:nth-child(4)::before {
color: gold;
z-index: 7;
height: calc(100% - 10% * 7);
}
.rainbow span:nth-child(4)::after {
color: tomato;
z-index: 8;
height: calc(100% - 10% * 8);
}
增加動畫效果:
.rainbow span::before,
.rainbow span::after {
animation: animate 0.8s infinite alternate;
filter: opacity(0);
}
@keyframes animate {
from {
filter: opacity(0);
}
to {
filter: opacity(1);
}
}
為圖層設置延時,增強動感:
.rainbow span:nth-child(1)::before {
animation-delay: calc(0.8s - 0.1s * 1);
}
.rainbow span:nth-child(1)::after {
animation-delay: calc(0.8s - 0.1s * 2);
}
.rainbow span:nth-child(2)::before {
animation-delay: calc(0.8s - 0.1s * 3);
}
.rainbow span:nth-child(2)::after {
animation-delay: calc(0.8s - 0.1s * 4);
}
.rainbow span:nth-child(3)::before {
animation-delay: calc(0.8s - 0.1s * 5);
}
.rainbow span:nth-child(3)::after {
animation-delay: calc(0.8s - 0.1s * 6);
}
.rainbow span:nth-child(4)::before {
animation-delay: calc(0.8s - 0.1s * 7);
}
.rainbow span:nth-child(4)::after {
animation-delay: calc(0.8s - 0.1s * 8);
}
最后,把原始文本設置為透明色:
.rainbow {
color: transparent;
}
大功告成!
知識點content https://developer.mozilla.org/en-US/docs/Web/CSS/content
attr() https://developer.mozilla.org/en-US/docs/Web/CSS/attr
calc() https://developer.mozilla.org/en-US/docs/Web/CSS/calc
z-index https://developer.mozilla.org/en-US/docs/Web/CSS/z-index
:nth-child() https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://m.hztianpu.com/yun/113283.html
摘要:效果預覽按下右側的點擊預覽按鈕可以在當前頁面預覽,點擊鏈接可以全屏預覽。可交互視頻教程此視頻是可以交互的,你可以隨時暫停視頻,編輯視頻中的代碼。 showImg(https://segmentfault.com/img/bVbbyt5?w=500&h=500); 效果預覽 按下右側的點擊預覽按鈕可以在當前頁面預覽,點擊鏈接可以全屏預覽。 https://codepen.io/comeh...
摘要:過往項目年月份項目匯總共個項目年月份發布的項目前端每日實戰專欄每天分解一個前端項目,用視頻記錄編碼過程,再配合詳細的代碼解讀,是學習前端開發的活的參考書頻演示如何用純創作一種按鈕被瞄準的交互特效視頻演示如何用純創作一個同心圓弧旋轉特效視頻演 過往項目 2018 年 4 月份項目匯總(共 8 個項目) 2018 年 5 月份發布的項目 《前端每日實戰》專欄每天分解一個前端項目,用視頻記錄...
摘要:過往項目年月份項目匯總共個項目年月份發布的項目前端每日實戰專欄每天分解一個前端項目,用視頻記錄編碼過程,再配合詳細的代碼解讀,是學習前端開發的活的參考書頻演示如何用純創作一種按鈕被瞄準的交互特效視頻演示如何用純創作一個同心圓弧旋轉特效視頻演 過往項目 2018 年 4 月份項目匯總(共 8 個項目) 2018 年 5 月份發布的項目 《前端每日實戰》專欄每天分解一個前端項目,用視頻記錄...
閱讀 2731·2021-11-24 09:39
閱讀 3215·2021-10-15 09:39
閱讀 3404·2021-07-26 23:38
閱讀 2492·2019-08-30 11:14
閱讀 3537·2019-08-29 16:39
閱讀 1853·2019-08-29 15:23
閱讀 991·2019-08-29 13:01
閱讀 2849·2019-08-29 12:29