佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > CSS實(shí)現(xiàn)漂亮的時(shí)鐘動(dòng)畫效果的實(shí)例代碼

CSS實(shí)現(xiàn)漂亮的時(shí)鐘動(dòng)畫效果的實(shí)例代碼

熱門標(biāo)簽:百度競(jìng)價(jià)排名 網(wǎng)站文章發(fā)布 太平洋壽險(xiǎn)電話營(yíng)銷 企業(yè)做大做強(qiáng) 團(tuán)購網(wǎng)站 網(wǎng)站排名優(yōu)化 科大訊飛語音識(shí)別系統(tǒng) 國美全國運(yùn)營(yíng)中心

我要找工作 !!!

預(yù)先準(zhǔn)備:

首先這個(gè)動(dòng)畫,是根據(jù)之前的 Loading 動(dòng)畫制作的,Loading炫酷動(dòng)畫, 這些的思路都是一樣的,在這個(gè)動(dòng)畫上進(jìn)行了一次創(chuàng)新。

預(yù)習(xí)知識(shí)點(diǎn):

  • 動(dòng)畫幀
  • 背景漸變
  • var() 和 calc() 的使用
  • flex布局的場(chǎng)景
  • 多個(gè)動(dòng)畫操作
  • 延遲動(dòng)畫的使用 

開始

核心代碼分析

transform: rotate(calc(30deg * var(--i)));
        transform-origin: 0 250px;
        animation: rotate 5s linear infinite;
        animation-delay: calc(0.42s * var(--i));

根據(jù)在 HTML 上搭建的style 樣式, 獲取每個(gè)對(duì)應(yīng)的i值, 分別計(jì)算每個(gè)時(shí)刻盒子的旋轉(zhuǎn)度數(shù), 同時(shí)我們更改他們的初始旋轉(zhuǎn)點(diǎn), 不然每個(gè)都只是中心旋轉(zhuǎn), 轉(zhuǎn)成了一個(gè)圓形。

思路還是loading的制作思路, 只不過這次尺寸比例放大了,

HTML代碼搭建:

<div class="box">
            <div class="color" style="--i:1">1</div>
            <div class="color" style="--i:2">2</div>
            <div class="color" style="--i:3">3</div>
            <div class="color" style="--i:4">4</div>
            <div class="color" style="--i:5">5</div>
            <div class="color" style="--i:6">6</div>
            <div class="color" style="--i:7">7</div>
            <div class="color" style="--i:8">8</div>
            <div class="color" style="--i:9">9</div>
            <div class="color" style="--i:10">10</div>
            <div class="color" style="--i:11">11</div>
            <div class="color" style="--i:12">12</div>
            <div class="hours"></div>
            <div class="mintues"></div>
        </div>

Less代碼:

* {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
}

body {
  background: -webkit-linear-gradient(left top, pink, rgb(90, 83, 83));
  display: flex;
  min-height: 100vh;
  justify-content: center;
  align-items: center;

  section {
    height: 500px;
    width: 500px;
    .box {
      position: relative;
      height: 500px;
      width: 500px;
      display: flex;
      justify-content: center;
      align-items: center;
      border: 5px solid #e2adb6;
      border-radius: 50%;
      // border: 2px solid red;
      &:hover .color {
        animation-play-state: paused;
      }

      &::after {
        content: "";
        display: block;
        height: 25px;
        width: 25px;
        background-color: #000;
        z-index: 4;
        border-radius: 50%;
      }

      @keyframes rotate {
        0%,
        50% {
          text-shadow: none;
          color: #000;
          transform: rotate(calc(30deg * var(--i))) scale(1);
        }

        50.1%,
        100% {
          text-shadow: 0 0 10px #000,
            0 0 15px #000;
          color: #fff;
          transform: rotate(calc(30deg * var(--i))) scale(1.01);
        }
      }

      .color {
        position: absolute;
        top: 0;
        color: #f2f2f2;
        opacity: .6;
        font-size: 20px;
        transform: rotate(calc(30deg * var(--i)));
        transform-origin: 0 250px;
        line-height: 50px;
        animation: rotate 5s linear infinite;
        animation-delay: calc(0.42s * var(--i));
      }

      @keyframes change1 {
        0% {
          transform: translateY(-50%) rotate(0deg);
          transform-origin: 0 100px;
        }

        100% {
          transform: translateY(-50%) rotate(360deg);
          transform-origin: 0 100px;
        }
      }

      @keyframes change2 {
        0% {
          transform: translateY(-50%) rotate(-30deg) rotate(0deg);
          transform-origin: 0 150px;
        }

        100% {
          transform: translateY(-50%) rotate(-30deg) rotate(360deg);
          transform-origin: 0 150px;
        }
      }

      .hours {
        position: absolute;
        top: 40%;
        width: 5px;
        transform: translateY(-50%);
        height: 100px;
        background-color: #f2f2f2;
        animation: change1 24s linear infinite;

        &::after {
          content: "";
          position: absolute;
          top: 0;
          left: -10px;
          width: 20px;
          height: 20px;
          border-bottom: 5px solid #f2f2f2;
          border-right: 5px solid #f2f2f2;
          transform: rotate(-135deg);
        }
      }

      .mintues {
        position: absolute;
        top: 36%;
        width: 3px;
        height: 150px;
        background-color: #000;
        transform: translateY(-50%) rotate(-30deg);
        transform-origin: 0 150px;
        animation: change2 2s linear infinite;

        &::after {
          content: "";
          position: absolute;
          top: 0;
          left: -10px;
          // display: block;
          width: 20px;
          height: 20px;
          border-bottom: 3px solid #000;
          border-right: 3px solid #000;
          transform: rotate(-135deg);
        }
      }
    }
  }
}

到此這篇關(guān)于CSS實(shí)現(xiàn)漂亮的時(shí)鐘動(dòng)畫效果的實(shí)例代碼的文章就介紹到這了,更多相關(guān)css時(shí)鐘動(dòng)畫內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!

標(biāo)簽:大同 泰州 萍鄉(xiāng) 赤峰 林芝 延邊 保定

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《CSS實(shí)現(xiàn)漂亮的時(shí)鐘動(dòng)畫效果的實(shí)例代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    龙胜| 区。| 高州市| 姚安县| 彭水| 塘沽区| 行唐县| 宜兰县| 柘荣县| 英吉沙县| 融水| 女性| 浪卡子县| 阿勒泰市| 确山县| 沾益县| 应用必备| 白河县| 赣榆县| 湖北省| 确山县| 米林县| 鸡西市| 铁力市| 诸暨市| 图片| 梁河县| 古浪县| 富民县| 惠来县| 武夷山市| 阳原县| 阳西县| 五大连池市| 密山市| 谢通门县| 云南省| 和静县| 彰化市| 泽州县| 扎鲁特旗|