成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

前端 CSS : 4# CSS 實現(xiàn)暖暖的小火堆

malakashi / 957人閱讀

摘要:介紹原文鏈接感謝大佬的前端每日實戰(zhàn)效果預覽瀏覽源代碼地址代碼解讀首先是完成結構常規(guī)樣式初始化天上的星星原文中星星是固定位置并且不會閃爍的而這里我們將會改變這一狀態(tài)而且為了避免重復手動給星星固定位置及大小所以采用了庫來減少麻煩首先將改

介紹
原文鏈接

感謝 comehope 大佬的 [前端每日實戰(zhàn)]

效果預覽

github.io 瀏覽
源代碼地址

https://github.com/shanyuhai1...

代碼解讀 1. 首先是完成 html 結構

常規(guī)樣式初始化

* {
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  padding: 0 0.5vw;
  height: 100vh;
  background-color: #333;
  overflow: hidden;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
2. 天上的星星

原文中星星是固定位置并且不會閃爍的

而這里我們將會改變這一狀態(tài), 而且為了避免重復手動給星星固定位置及大小, 所以采用了 d3 庫來減少麻煩

首先將 .stars 改為 grid 布局

使用 span 標簽 作為星星

因為星星要分時間閃爍所以隨機一個 --delay 參數(shù)

// index.js
const COLUMNS = 15;

d3.select(".stars")
  .style("--columns", COLUMNS)
  .selectAll("span")
  .data(d3.range(COLUMNS * COLUMNS))
  .enter()
  .append("span")
  .style("--delay", () => Math.random() * 20);

先給出大概的范圍, 查看下邊界

.stars {
  width: 99vw;
  height: 70vh;
  position: absolute;
  display: grid;
  grid-template-columns: repeat(var(--columns), 1fr);
  border: 1px solid;
}

.stars span {
  width: 0.6vw;
  height: 0.6vw;
  color: whitesmoke;
  background-color: currentColor;
}

星星現(xiàn)在只是一個個正方形, 再給正方形添加上旋轉閃現(xiàn)的動畫即可

.stars span {
  transform: scale(0);
  animation: spin 20s linear infinite;
  animation-delay: calc(var(--delay) * 1s);
}

@keyframes spin {
  0% {
    transform: rotate(0deg) scale(1);
  }

  5%,
  15% {
    transform: rotate(90deg) scale(0);
    background: goldenrod;
  }

  17.5% {
    transform: rotate(180deg) scale(1);
    background-color: currentColor;
  }

  20%,
  100% {
    transform: rotate(90deg) scale(0);
  }
}
3. 添加火堆

首先是修改 DOM

使火堆居中, 利用媒體查詢改變一下在手機端偏小的問題

.fires {
  position: relative;
  border: 1px solid;
}

@media screen and (min-width: 451px) {
  .fires {
    width: 15vw;
    height: 15vw;
    margin-top: -7vw;
  }
}
@media screen and (max-width: 450px) {
  .fires {
    width: 18vh;
    height: 18vh;
    margin-top: -5vw;
  }
}

接著完成火焰效果, 在父級添加可用的 color , border-radius 變量

.fires {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid;
  --color-one: #D92B29;
  --color-two: #F5732A;
  --color-three: #F2B338;
  --color-four: #F5D549;
  --shape-one: 79% 21% 64% 36% / 43% 61% 39% 57%;
  --shape-two: 23% 77% 66% 34% / 57% 72% 28% 43%;
  --shape-three: 78% 22% 63% 37% / 39% 27% 73% 61%;
  --shape-four: 35% 65% 78% 22% / 54% 50% 50% 46%;
}

@media screen and (min-width: 451px) {
  .fires__flame {
    width: 6vw;
  }
  .fires__flame:nth-of-type(1) {
    height: 15vw;
  }
  .fires__flame:nth-of-type(2) {
    height: 12vw;
    transform: translate(2.25vw, 1.2vw) rotate(30deg);
  }
  .fires__flame:nth-of-type(3) {
    height: 13.5vw;
    transform: translate(-2.25vw, 1.2vw) rotate(-30deg);
  }
  .fires__flame:nth-of-type(4) {
    height: 10.5vw;
  }
}
@media screen and (max-width: 450px) {
  .fires__flame {
    width: 7.2vh;
  }
  .fires__flame:nth-of-type(1) {
    height: 18vh;
  }
  .fires__flame:nth-of-type(2) {
    height: 14.4vh;
    transform: translate(2.7vh, 1.44vh) rotate(30deg);
  }
  .fires__flame:nth-of-type(3) {
    height: 16.2vh;
    transform: translate(-2.7vh, 1.44vh) rotate(-30deg);
  }
  .fires__flame:nth-of-type(4) {
    height: 12.6vh;
  }
}

.fires__flame {
  position: absolute;
  background-color: var(--color-one);
  border-radius: var(--shape-one);
  z-index: 0;
  animation-name: fire;
  animation-duration: 1.5s;
  animation-iteration-count: infinite;
  transition: ease 0.4s;
}
.fires__flame:nth-of-type(2) {
  border-radius: var(--shape-two);
  background-color: var(--color-two);
  opacity: 0.9;
  z-index: 2;
  animation-delay: 0.2s;
}
.fires__flame:nth-of-type(3) {
  border-radius: var(--shape-three);
  background-color: var(--color-three);
  opacity: 0.8;
  z-index: 1;
  animation-delay: 0.4s;
}
.fires__flame:nth-of-type(4) {
  border-radius: var(--shape-four);
  background-color: var(--color-four);
  opacity: 0.8;
  z-index: 1;
  animation-delay: 0.6s;
}

當然別忘了火焰的動畫效果

@keyframes fire {
  0% {
    border-radius: var(--shape-one);
    background-color: var(--color-one);
  }
  25% {
    border-radius: var(--shape-two);
    background-color: var(--color-two);
  }
  50% {
    border-radius: var(--shape-three);
    background-color: var(--color-three);
  }
  75% {
    border-radius: var(--shape-four);
    background-color: var(--color-four);
  }
  100% {
    border-radius: var(--shape-one);
    background-color: var(--color-one);
  }
}

再添加木柴

@media screen and (min-width: 451px) {
  .fires__stick {
    border-radius: 1.5vw;
    width: 3vw;
    height: 13.5vw;
    bottom: -7.5vw;
  }
}
@media screen and (max-width: 450px) {
  .fires__stick {
    border-radius: 1.8vh;
    width: 3.6vh;
    height: 16.2vh;
    bottom: -9vh;
  }
}

.fires__stick {
  background-color: #5a3600;
  position: absolute;
  z-index: 2;
  transform:rotate(-70deg);
}
.fires__stick:last-of-type {
  transform:rotate(70deg);
  background-color: #4e2f01;
}
4. 最后

最后記得把之前確認位置及大小的 border 邊框刪除即可

文章版權歸作者所有,未經(jīng)允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉載請注明本文地址:http://systransis.cn/yun/117129.html

相關文章

  • 利用CSS改變圖片顏色的100種方法!

    摘要:前言說到對圖片進行處理,我們經(jīng)常會想到這類的圖像處理工具?;蛘呤堑臅r候,對圖片的對比度,陰影進行處理。過濾器通常被用于調整圖片,背景和邊界的渲染。最后,安利我們的公眾號前端指南。 前言 說到對圖片進行處理,我們經(jīng)常會想到PhotoShop這類的圖像處理工具。作為前端開發(fā)者,我們經(jīng)常會需要處理一些特效,例如根據(jù)不同的狀態(tài),讓圖標顯示不同的顏色?;蛘呤莌over的時候,對圖片的對比度,陰影...

    Keven 評論0 收藏0
  • 利用CSS改變圖片顏色的100種方法!

    摘要:前言說到對圖片進行處理,我們經(jīng)常會想到這類的圖像處理工具?;蛘呤堑臅r候,對圖片的對比度,陰影進行處理。過濾器通常被用于調整圖片,背景和邊界的渲染。最后,安利我們的公眾號前端指南。 前言 說到對圖片進行處理,我們經(jīng)常會想到PhotoShop這類的圖像處理工具。作為前端開發(fā)者,我們經(jīng)常會需要處理一些特效,例如根據(jù)不同的狀態(tài),讓圖標顯示不同的顏色?;蛘呤莌over的時候,對圖片的對比度,陰影...

    pinecone 評論0 收藏0
  • 用Node EJS寫一個爬蟲腳本每天定時給心愛的她發(fā)一封暖心郵件

    摘要:本文首發(fā)于個人博客項目源碼,歡迎,說不定哪天脫單了就能用到了寫在前面自從用郵箱注冊了很多賬號后,便會收到諸如以下類似的郵件剛開始還以為是一張圖片,后來仔細一看不是圖片呀,好像還是呀,于是好奇寶寶我一下,查閱多篇資料后總結出怎么用前端知識和做 本文首發(fā)于個人博客:VinceBlog 項目源碼:NodeMail,歡迎star,說不定哪天脫單了就能用到了 寫在前面 自從用郵箱注冊了很多賬號后...

    zero 評論0 收藏0
  • 2017文章總結

    摘要:歡迎來我的個人站點性能優(yōu)化其他優(yōu)化瀏覽器關鍵渲染路徑開啟性能優(yōu)化之旅高性能滾動及頁面渲染優(yōu)化理論寫法對壓縮率的影響唯快不破應用的個優(yōu)化步驟進階鵝廠大神用直出實現(xiàn)網(wǎng)頁瞬開緩存網(wǎng)頁性能管理詳解寫給后端程序員的緩存原理介紹年底補課緩存機制優(yōu)化動 歡迎來我的個人站點 性能優(yōu)化 其他 優(yōu)化瀏覽器關鍵渲染路徑 - 開啟性能優(yōu)化之旅 高性能滾動 scroll 及頁面渲染優(yōu)化 理論 | HTML寫法...

    dailybird 評論0 收藏0

發(fā)表評論

0條評論

malakashi

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<