摘要:效果預(yù)覽按下右側(cè)的點(diǎn)擊預(yù)覽按鈕可以在當(dāng)前頁面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽??山换ヒ曨l此視頻是可以交互的,你可以隨時暫停視頻,編輯視頻中的代碼。
效果預(yù)覽
按下右側(cè)的“點(diǎn)擊預(yù)覽”按鈕可以在當(dāng)前頁面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽。
https://codepen.io/comehope/pen/zJKwbO
可交互視頻此視頻是可以交互的,你可以隨時暫停視頻,編輯視頻中的代碼。
請用 chrome, safari, edge 打開觀看。
https://scrimba.com/p/pEgDAM/cDBZNUW
源代碼下載每日前端實(shí)戰(zhàn)系列的全部源代碼請從 github 下載:
https://github.com/comehope/front-end-daily-challenges
代碼解讀定義 dom,容器中包含 8 個元素,每個元素代表一個矩形色塊:
居中顯示:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: #ccc; }
定義容器尺寸:
.icon { width: 10em; height: 10em; font-size: 30px; background-color: #eee; border-radius: 20%; }
繪制出矩形的輪廓(邊框?yàn)檩o助線,最終會被刪除),并放置在容器的中上方:
.icon { position: relative; display: flex; justify-content: center; box-sizing: border-box; padding: 1em; } .icon span { position: absolute; width: 22.5%; height: 37.5%; border: 1px dashed black; border-radius: 50% / 30%; }
為矩形設(shè)置下標(biāo)變量 --n:
.icon span:nth-child(1) { --n: 1; } .icon span:nth-child(2) { --n: 2; } .icon span:nth-child(3) { --n: 3; } .icon span:nth-child(4) { --n: 4; } .icon span:nth-child(5) { --n: 5; } .icon span:nth-child(6) { --n: 6; } .icon span:nth-child(7) { --n: 7; } .icon span:nth-child(8) { --n: 8; }
讓 8 個矩形依次旋轉(zhuǎn)固定的角度,圍合成一個圓形:
.icon span { transform-origin: center 105%; transform: rotate(calc((var(--n) - 1) * 45deg)); }
為矩形設(shè)置顏色變量 --c:
.icon span:nth-child(1) { --c: rgba(243, 156, 18, 0.7); } .icon span:nth-child(2) { --c: rgba(241, 196, 15, 0.7); } .icon span:nth-child(3) { --c: rgba(46, 204, 113, 0.7); } .icon span:nth-child(4) { --c: rgba(27, 188, 155, 0.7); } .icon span:nth-child(5) { --c: rgba(65, 131, 215, 0.7); } .icon span:nth-child(6) { --c: rgba(102, 51, 153, 0.7); } .icon span:nth-child(7) { --c: rgba(155, 89, 182, 0.7); } .icon span:nth-child(8) { --c: rgba(242, 38, 19, 0.7); }
為 8 個矩形上色,并刪除掉起輔助線作用的邊框:
.icon span { /* border: 1px dashed black; */ background-color: var(--c); }
設(shè)置混色模式,使重疊顏色能疊加在一起:
.icon span { mix-blend-mode: multiply; }
增加鼠標(biāo)懸停效果,當(dāng)懸停時運(yùn)行矩形色塊展開的動畫:
.icon:hover span { animation: rotating 2s ease-in-out forwards; } @keyframes rotating { from { transform: rotate(0deg); } to { transform: rotate(calc((var(--n) - 1) * 45deg)); } }
注意,在動畫過程中第 1 個矩形并沒有轉(zhuǎn)動,因?yàn)樗菑?0 度轉(zhuǎn)到 0 度,為了讓它轉(zhuǎn)動,要把它的結(jié)束角度設(shè)置為 360 度,通過修改它的下標(biāo)變量來實(shí)現(xiàn):
.icon span:nth-child(1) { --n: 9; }
大功告成!
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/52946.html
摘要:效果預(yù)覽按下右側(cè)的點(diǎn)擊預(yù)覽按鈕可以在當(dāng)前頁面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽??山换ヒ曨l此視頻是可以交互的,你可以隨時暫停視頻,編輯視頻中的代碼。 showImg(https://segmentfault.com/img/bVbgbWF?w=400&h=302); 效果預(yù)覽 按下右側(cè)的點(diǎn)擊預(yù)覽按鈕可以在當(dāng)前頁面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽。 https://codepen.io/comehop...
摘要:過往項(xiàng)目年月份項(xiàng)目匯總共個項(xiàng)目年月份項(xiàng)目匯總共個項(xiàng)目年月份項(xiàng)目匯總共個項(xiàng)目年月份項(xiàng)目匯總共個項(xiàng)目年月份項(xiàng)目匯總共個項(xiàng)目年月份項(xiàng)目匯總共個項(xiàng)目年月至年月發(fā)布的項(xiàng)目前端每日實(shí)戰(zhàn)專欄每天分解一個前端項(xiàng)目,用視頻記錄編碼過程,再配合詳細(xì)的代碼解讀, 過往項(xiàng)目 2018 年 9 月份項(xiàng)目匯總(共 26 個項(xiàng)目) 2018 年 8 月份項(xiàng)目匯總(共 29 個項(xiàng)目) 2018 年 7 月份項(xiàng)目匯總(...
摘要:效果預(yù)覽按下右側(cè)的點(diǎn)擊預(yù)覽按鈕可以在當(dāng)前頁面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽。可交互視頻教程此視頻是可以交互的,你可以隨時暫停視頻,編輯視頻中的代碼。 showImg(https://segmentfault.com/img/bVbbys8?w=500&h=500); 效果預(yù)覽 按下右側(cè)的點(diǎn)擊預(yù)覽按鈕可以在當(dāng)前頁面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽。 https://codepen.io/comeh...
閱讀 1998·2021-11-24 09:39
閱讀 992·2021-11-11 16:55
閱讀 1449·2021-10-09 09:43
閱讀 1434·2021-10-08 10:17
閱讀 1668·2021-08-25 09:41
閱讀 439·2019-08-30 13:02
閱讀 641·2019-08-29 15:14
閱讀 1017·2019-08-29 13:53